refactor: route atomic writes through one helper

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:00:14 +01:00
1 parent 856883f690
commit 434d660647
7 files changed
+59 -111

No files matched your search

+3 -4
View File
@@ -4,9 +4,10 @@ from __future__ import annotations
import datetime as dt
import json
import os
from pathlib import Path
from core.artifacts import write_text_atomic
def now_iso() -> str:
return dt.datetime.now(dt.timezone.utc).replace(microsecond=0).isoformat()
@@ -14,6 +15,4 @@ def now_iso() -> str:
def save_state(path: Path, state: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
scratch = path.with_suffix(".tmp")
scratch.write_text(json.dumps(state, indent=2, sort_keys=True) + "\n", encoding="utf-8")
os.replace(scratch, path)
write_text_atomic(path, json.dumps(state, indent=2, sort_keys=True) + "\n")