Spaces:
Sleeping
Sleeping
Kennedy Johnson Cursor commited on
Commit ·
71de506
1
Parent(s): 5c21ffd
Fallback to writable data dir when /data is not mountable on HF Spaces.
Browse files
multi_llm_chatbot_backend/app/core/db.py
CHANGED
|
@@ -89,9 +89,18 @@ _TABLE_NAMES = {t[0] for t in _TABLES}
|
|
| 89 |
|
| 90 |
def _data_dir() -> Path:
|
| 91 |
raw = os.environ.get("DATA_DIR") or "/data"
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
def _db_path() -> Path:
|
|
|
|
| 89 |
|
| 90 |
def _data_dir() -> Path:
|
| 91 |
raw = os.environ.get("DATA_DIR") or "/data"
|
| 92 |
+
candidates = [Path(raw).expanduser()]
|
| 93 |
+
if str(candidates[0]) == "/data":
|
| 94 |
+
candidates.append(Path.home() / "data")
|
| 95 |
+
for p in candidates:
|
| 96 |
+
try:
|
| 97 |
+
p.mkdir(parents=True, exist_ok=True)
|
| 98 |
+
return p
|
| 99 |
+
except PermissionError:
|
| 100 |
+
LOG.warning("Cannot create data dir %s; trying fallback", p)
|
| 101 |
+
fallback = Path("/tmp/data")
|
| 102 |
+
fallback.mkdir(parents=True, exist_ok=True)
|
| 103 |
+
return fallback
|
| 104 |
|
| 105 |
|
| 106 |
def _db_path() -> Path:
|