Skip to content

fix: make config file saves atomic#43

Open
echobt wants to merge 1 commit intomainfrom
fix/issue-134
Open

fix: make config file saves atomic#43
echobt wants to merge 1 commit intomainfrom
fix/issue-134

Conversation

@echobt
Copy link
Copy Markdown
Contributor

@echobt echobt commented Jan 20, 2026

Description

This PR addresses issue #134 regarding non-atomic saves of configuration files. Previously, config files were written directly, which could lead to corruption if the process was interrupted during the write operation.

Changes

  • Added uuid dependency to generate unique temporary filenames.
  • Implemented write_atomic helper function in a new utils.rs module.
  • write_atomic writes content to a temporary file first, then renames it to the target path.
  • Updated Config::save in src/config.rs to use write_atomic.
  • Updated various config writing operations in src/cli/install.rs to use write_atomic.

Verification

  • Added a temporary test suite tests/atomic_write_test.rs to verify the atomic write behavior (creates file, overwrites file, handles directories).
  • Ran cargo test successfully.
  • Verified that existing tests pass.

This introduces a write_atomic helper that writes to a temporary file first and then renames it to the target path. This ensures that if the process is interrupted during write, the target file remains intact.
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.

1 participant