1
Offline regression tests / windows (3.11) (push) Canceled after 0s
Offline regression tests / windows (3.12) (push) Canceled after 0s
Offline regression tests / windows (3.13) (push) Canceled after 0s

This commit is contained in:
listik committed 2026-10-23 20:49:12 +03:00
1 parent 2ea1a79bda
commit 85425483c0
50 files changed
+6468 -1854

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
"""Atomic local JSON snapshots; callers must handle write failures explicitly."""
from __future__ import annotations
import json
import os
import tempfile
from pathlib import Path
def atomic_write_json(path: Path, payload) -> None:
"""Flush a new snapshot before replacing the old file, or leave the old file intact."""
path = Path(path)
encoded = json.dumps(payload, ensure_ascii=False, allow_nan=False).encode("utf-8")
path.parent.mkdir(parents=True, exist_ok=True)
fd, temporary = tempfile.mkstemp(prefix=path.name + ".", suffix=".tmp", dir=path.parent)
try:
with os.fdopen(fd, "wb") as stream:
stream.write(encoded)
stream.flush()
os.fsync(stream.fileno())
os.replace(temporary, path)
finally:
try:
os.unlink(temporary)
except FileNotFoundError:
pass