fix: prevent Ollama config refresh resets

This commit is contained in:
Hermes Agent
2026-08-24 23:07:28 +10:00
parent f45fbf0b1b
commit 73a38617e3
5 changed files with 21 additions and 9 deletions
+13 -5
View File
@@ -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: