feat: add atomic write utilities for safe file operations#5500
Merged
ruben-arts merged 2 commits intoprefix-dev:mainfrom Mar 3, 2026
Merged
feat: add atomic write utilities for safe file operations#5500ruben-arts merged 2 commits intoprefix-dev:mainfrom
ruben-arts merged 2 commits intoprefix-dev:mainfrom
Conversation
Write manifest files (pixi.toml, pyproject.toml, global manifest) via a temporary file in the same directory followed by an atomic rename. This prevents data loss when a write fails mid-operation (e.g. due to a full disk), since the original file remains untouched until the new content is fully written. Adds `pixi_utils::atomic_write` module with both async and sync variants, and updates all manifest write sites: - WorkspaceMut::save_inner() (async) - WorkspaceMut::revert() (async) - WorkspaceMut::Drop::drop() (sync) - pixi_global Manifest::save() (async) Closes prefix-dev#5463 https://claude.ai/code/session_019JHCPv8zTSRHkm5teuTyp6
180d92c to
477292a
Compare
ruben-arts
approved these changes
Mar 3, 2026
Contributor
ruben-arts
left a comment
There was a problem hiding this comment.
Changes make sense, I don't have the time to test it on a temp filesystem. But it doesn't break existing workflows so I'll approve it without validating that this solves the problem described in issue #5463. Let's see if the issue comes back.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces atomic write utilities to ensure safe file operations across the codebase. The changes add two new functions (
atomic_writeandatomic_write_sync) that write to a temporary file in the same directory and then atomically rename it to the target path. This prevents partial writes and ensures data integrity if operations fail (e.g., due to disk full).The implementation uses
tempfile::NamedTempFileto create temporary files in the same directory as the target, ensuring they're on the same filesystem for atomic rename operations. If the write fails, the temporary file is automatically cleaned up.Fixes #5463
How Has This Been Tested?
The changes replace existing file write operations with atomic variants. Existing tests that cover manifest saving and workspace operations will validate the new implementation. The atomic write functions maintain the same error handling semantics as the previous
fs_errcalls, ensuring compatibility with existing error handling paths.AI Disclosure
Written by Claude Code Opus 4.6 Extended.
Checklist: