Archive the raw transcript by content hash with its verdict, and stop on a failed archive

This commit is contained in:
2026-09-28 16:57:24 +02:00
parent 5e3b66232b
commit 6e31e0a833
7 changed files with 75 additions and 41 deletions
+6 -2
View File
@@ -11,12 +11,16 @@ def make_private(folder):
def replace_json(path, data, **dump):
return replace_file(path, json.dumps(data, **dump).encode())
def replace_file(path, data):
staged = f"{path}.{os.getpid()}"
try:
mode = os.stat(path).st_mode & 0o7777 if os.path.exists(path) else 0o600
with open(os.open(staged, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "w", encoding="utf-8") as handle:
with open(os.open(staged, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600), "wb") as handle:
os.fchmod(handle.fileno(), mode)
json.dump(data, handle, **dump)
handle.write(data)
os.replace(staged, path)
except OSError as failure:
if os.path.exists(staged):