Problem:
Writes directly to dump.json with no temp-file-then-rename pattern.
with open(filename, "w") as f:
json.dump(state, f)
Fix:
tmp = f"{filename}.tmp"
with open(tmp, "w") as f:
json.dump(state, f)
f.flush()
os.fsync(f.fileno())
os.replace(tmp, filename) # atomic on POSIX and Windows
Problem:
Writes directly to dump.json with no temp-file-then-rename pattern.
Fix: