Skip to content

Keep an existing file's mode when a local transaction commits - #2326

Merged
martindurant merged 2 commits into
fsspec:masterfrom
rajath201:local-commit-keep-mode
Nov 25, 2026
Merged

martindurant merged 2 commits into
fsspec:masterfrom
rajath201:local-commit-keep-mode

Conversation

@rajath201

Copy link
Copy Markdown
Contributor

LocalFileOpener.commit finishes every write made inside fs.transaction (or with autocommit=False) by moving a tempfile.mkstemp() file over the target and then chmod-ing it to 0o666 & ~umask. The move replaces the inode, so whatever mode the file had before is gone: a config or credentials file kept at 0o600 comes out of the transaction as 0o644, readable by every other user on the host, while a plain open(path, "wb") truncates in place and keeps 0o600.

Read the existing file's permission bits before the move and put them back afterwards; the umask default now only applies when there was no file, which is what test_same_permissions_with_and_without_transaction checks for new files. Added a regression test in test_local.py that fails without the change; pre-commit and the full suite pass locally.

@martindurant

Copy link
Copy Markdown
Member

Isn't it expected that a newly written file's mode would not depend on whatever file was there before?

@rajath201

Copy link
Copy Markdown
Contributor Author

For a fresh path, sure, and that case still gets the umask default. The thing is, a normal fs.open(path, "wb") on an existing file truncates in place, so its mode is already kept today. Only the transaction path swaps in a new inode. On master, with a file at 0o600:

fs.open(p, "wb")                    -> 0o600
with fs.transaction: fs.open(...)  -> 0o644

So whether a file stays private depends on whether it was written inside a transaction, and that bites most for configs and credentials. This is the same kind of parity test_same_permissions_with_and_without_transaction already checks for new files. If you'd rather a transaction always produce a fresh file, though, I'm fine closing this.

@rajath201

Copy link
Copy Markdown
Contributor Author

gentle ping

@martindurant
martindurant merged commit a229362 into fsspec:master Nov 25, 2026
9 checks passed
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.

2 participants