Skip to content

[BUG] SAVE command is non-atomic #10

Description

@Hogwarts-coder10

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

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions