This commit is contained in:
2026-01-11 00:52:54 -08:00
parent 6eb02f22b5
commit 7c1959483f
6 changed files with 51 additions and 32 deletions

View File

@@ -9,7 +9,7 @@ from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
from SYS.logger import debug, log
from SYS.utils import sha256_file
from SYS.utils import sha256_file, expand_path
from Store._base import Store
@@ -73,9 +73,8 @@ class Folder(Store):
try:
from API.folder import API_folder_store
from API.folder import LocalLibraryInitializer
from pathlib import Path
location_path = Path(self._location).expanduser()
location_path = expand_path(self._location)
# Use context manager to ensure connection is properly closed
with API_folder_store(location_path) as db:
@@ -124,9 +123,7 @@ class Folder(Store):
if not location:
return
from pathlib import Path
location_path = Path(location).expanduser()
location_path = expand_path(location)
location_str = str(location_path)
# Only migrate once per location
@@ -673,7 +670,7 @@ class Folder(Store):
match_all = query == "*" or (not query and bool(ext_filter))
results = []
search_dir = Path(self._location).expanduser()
search_dir = expand_path(self._location)
def _url_like_pattern(value: str) -> str:
# Interpret user patterns as substring matches (with optional glob wildcards).
@@ -1335,10 +1332,10 @@ class Folder(Store):
of the file path to find a directory with medios-macina.db."""
candidates: list[Path] = []
if self._location:
candidates.append(Path(self._location).expanduser())
candidates.append(expand_path(self._location))
cfg_root = get_local_storage_path(config) if config else None
if cfg_root:
candidates.append(Path(cfg_root).expanduser())
candidates.append(expand_path(cfg_root))
for root in candidates:
db_path = root / "medios-macina.db"
@@ -1369,7 +1366,7 @@ class Folder(Store):
if not normalized_hash:
return None
search_dir = Path(self._location).expanduser()
search_dir = expand_path(self._location)
from API.folder import API_folder_store
with API_folder_store(search_dir) as db:
@@ -1400,7 +1397,7 @@ class Folder(Store):
if not normalized_hash:
return None
search_dir = Path(self._location).expanduser()
search_dir = expand_path(self._location)
from API.folder import DatabaseAPI
with DatabaseAPI(search_dir) as api:
@@ -1460,7 +1457,7 @@ class Folder(Store):
from API.folder import API_folder_store
with API_folder_store(Path(self._location).expanduser()) as db:
with API_folder_store(expand_path(self._location)) as db:
db.set_relationship_by_hash(
alt_norm,
king_norm,
@@ -2150,7 +2147,7 @@ class Folder(Store):
if not raw:
return False
store_root = Path(self._location).expanduser()
store_root = expand_path(self._location)
# Support deletion by hash (common for store items where `path` is the hash).
file_hash = _normalize_hash(raw)
@@ -2159,7 +2156,7 @@ class Folder(Store):
if file_hash:
resolved_path = db.search_hash(file_hash)
else:
p = Path(raw)
p = expand_path(raw)
resolved_path = p if p.is_absolute() else (store_root / p)
if resolved_path is None:

View File

@@ -19,6 +19,7 @@ from pathlib import Path
from typing import Any, Dict, Iterable, Optional, Type
from SYS.logger import debug
from SYS.utils import expand_path
from Store._base import Store as BaseStore
@@ -169,8 +170,8 @@ class Store:
if not path_value:
return
temp_path = Path(str(temp_value)).expanduser().resolve()
backend_path = Path(str(path_value)).expanduser().resolve()
temp_path = expand_path(temp_value).resolve()
backend_path = expand_path(path_value).resolve()
if backend_path != temp_path:
return
@@ -230,7 +231,7 @@ class Store:
for key in list(kwargs.keys()):
if _normalize_config_key(key) in {"PATH",
"LOCATION"}:
kwargs[key] = str(Path(str(kwargs[key])).expanduser())
kwargs[key] = str(expand_path(kwargs[key]))
backend = store_cls(**kwargs)
@@ -411,7 +412,7 @@ def list_configured_backend_names(config: Optional[Dict[str, Any]]) -> list[str]
try:
temp_value = (config or {}).get("temp")
if temp_value:
temp_path = str(Path(str(temp_value)).expanduser().resolve())
temp_path = str(expand_path(temp_value).resolve())
for raw_store_type, instances in store_cfg.items():
if not isinstance(instances, dict):
continue
@@ -423,7 +424,7 @@ def list_configured_backend_names(config: Optional[Dict[str, Any]]) -> list[str]
path_value = instance_config.get("PATH") or instance_config.get("path")
if not path_value:
continue
if str(Path(str(path_value)).expanduser().resolve()) == temp_path:
if str(expand_path(path_value).resolve()) == temp_path:
if "temp" not in names:
names.append("temp")
except Exception: