Skip to content

Make JSON file writes atomic#419

Open
giwaov wants to merge 1 commit into
canopy-network:mainfrom
giwaov:issue-189-atomic-json-writes
Open

Make JSON file writes atomic#419
giwaov wants to merge 1 commit into
canopy-network:mainfrom
giwaov:issue-189-atomic-json-writes

Conversation

@giwaov

@giwaov giwaov commented Jun 25, 2026

Copy link
Copy Markdown

Summary

  • Add an atomic file-write helper that writes through a temporary file in the destination directory before renaming it into place.
  • Use the helper for shared JSON persistence, config writes, and peer-book writes.
  • Add focused coverage for replacement behavior and parent directory creation.

Why

Fixes #189. A crash or interrupted write could leave persisted JSON files such as the peer book truncated, causing startup failures when the file was read again.

Testing

  • git diff --check

Go tests were not run locally because go is not installed on this machine.

@giwaov giwaov marked this pull request as ready for review June 25, 2026 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Make writing data directory JSON files atomic (Book.json, Config.json etc.)

1 participant