fix: preserve POSIX permissions during atomic file writes - #17
Merged
irmia2026 merged 1 commit intoAug 17, 2026
Merged
Conversation
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.
Summary
0644mode for newly created files.multi_edit, which has its own atomic commit path.Problem
The file tools write through a temporary file created by
tempfile.mkstemp()and then commit it withos.replace().On POSIX systems,
mkstemp()creates the temporary file with mode0600. Becauseos.replace()moves that inode into the destination path, the final user file also becomes0600, regardless of the process umask.This can make generated files unreadable to downstream processes running under another UID. It also silently removes existing modes such as
0640or executable bits.safe_write,safe_edit, andfile_patchshareatomic_write_text().multi_editimplements a separatemkstemp()/os.replace()commit path and therefore requires the same handling independently.Changes
_atomic_target_mode():Noneon non-POSIX platforms;rwxpermission bits;0644when creating a new file.os.replace().multi_edit.0600,0640, and0755modes.Applying the mode before replacement is intentional: if
chmod()fails, the original target remains untouched and the existing rollback behavior is preserved.Verification
62 passed143 passed, 2 skipped657 passed, 2 skipped, 1 deselectedAn isolated Linux probe also confirmed that new files are
0644under umask000,022, and077, while existing private files retain their original mode.Scope
This change preserves traditional POSIX
rwxpermission bits. It deliberately does not copy ownership, ACLs, extended attributes, or setuid/setgid/sticky bits. Windows behavior is unchanged.