mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-29 04:48:54 -06:00
refactor: route atomic writes through one helper
This commit is contained in:
1 parent
856883f690
commit
434d660647
7 files changed
+59
-111
No files matched your search
@@ -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")
|
||||
Reference in new issue
Block a user