fix: prevent Ollama config refresh resets
This commit is contained in:
+13
-5
@@ -262,8 +262,11 @@ FAMILY_STRENGTHS = {
|
||||
}
|
||||
|
||||
|
||||
_PLUGIN_HOME_ROOT = Path(os.environ.get("HERMES_HOME", "").strip()).expanduser().resolve() if os.environ.get("HERMES_HOME", "").strip() else Path(get_hermes_home()).resolve()
|
||||
|
||||
|
||||
def _home() -> Path:
|
||||
path = get_hermes_home() / "ollama-manager"
|
||||
path = _PLUGIN_HOME_ROOT / "ollama-manager"
|
||||
path.mkdir(parents=True, exist_ok=True)
|
||||
return path
|
||||
|
||||
@@ -296,11 +299,16 @@ def _read_connections() -> dict[str, str]:
|
||||
|
||||
def _write_connections(value: dict[str, str]) -> None:
|
||||
path = _home() / CONNECTIONS_FILE
|
||||
path.write_text(json.dumps(value, indent=2) + "\n", encoding="utf-8")
|
||||
temporary = path.with_name(f".{path.name}.{os.getpid()}.tmp")
|
||||
temporary.write_text(json.dumps(value, indent=2) + "\n", encoding="utf-8")
|
||||
try:
|
||||
path.chmod(0o600)
|
||||
except OSError:
|
||||
pass
|
||||
temporary.chmod(0o600)
|
||||
os.replace(temporary, path)
|
||||
finally:
|
||||
try:
|
||||
temporary.unlink()
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def _apply_saved_connection() -> None:
|
||||
|
||||
Reference in New Issue
Block a user