fix(portable): use project root for settings storage

This commit is contained in:
pixelpaws
2025-11-02 09:07:57 +08:00
parent ee18cff3d9
commit 285428ad3a
5 changed files with 50 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ import threading
from dataclasses import dataclass
from typing import Dict, List, Optional, Sequence, Tuple
from ..utils.settings_paths import get_settings_dir
from ..utils.settings_paths import get_project_root, get_settings_dir
logger = logging.getLogger(__name__)
@@ -397,7 +397,7 @@ class PersistentModelCache:
settings_dir = get_settings_dir(create=True)
except Exception as exc: # pragma: no cover - defensive guard
logger.warning("Falling back to project directory for cache: %s", exc)
settings_dir = os.path.dirname(os.path.dirname(self._db_path)) if hasattr(self, "_db_path") else os.getcwd()
settings_dir = get_project_root()
safe_name = re.sub(r"[^A-Za-z0-9_.-]", "_", library_name or "default")
if safe_name.lower() in ("default", ""):
legacy_path = os.path.join(settings_dir, self._DEFAULT_FILENAME)

View File

@@ -37,8 +37,13 @@ def get_settings_dir(create: bool = True) -> str:
The absolute path to the user configuration directory.
"""
config_dir = user_config_dir(APP_NAME, appauthor=False)
if create:
legacy_path = get_legacy_settings_path()
if _should_use_portable_settings(legacy_path, _LOGGER):
config_dir = os.path.dirname(legacy_path)
else:
config_dir = user_config_dir(APP_NAME, appauthor=False)
if create and config_dir:
os.makedirs(config_dir, exist_ok=True)
return config_dir