Repository navigation
fix: keep a file's owner when CookCLI rewrites it - #819
Merged
Merged
Conversation
Rewriting `.shopping-list`, `.shopping-checked` or `pantry.conf` renamed a new file over the old one, which hands it to whoever `cook` runs as. On a network share mounted into Docker that is the share's mount account, and the sync client then fails with "Permission denied". Write through the existing file instead when a rename would change its owner or group, or when it lives on SMB/CIFS or NFS, after the temporary file has shown the bytes fit on the disk. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B7jPFNJkuXkHhuXsLYLrQw
Saving a recipe or menu in the editor, editing a plan, replacing a picture, writing aisle.conf and rewriting references after a rename all renamed a new file over the old one, so the file became the server user's. On a network share mounted into Docker that locks the share's other users and the sync client out, as with the shopping list. All of them now go through `fs_atomic::write_replace`, which writes in place when a rename would change the owner or group, or on SMB/CIFS and NFS. The editor save also gains the permission carry-over and fsync it lacked, and no longer leaves a visible `Recipe.tmp` beside the recipe. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B7jPFNJkuXkHhuXsLYLrQw
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
A removed `.shopping-checked` came back with the next tick as a new file owned by whoever `cook` runs as. Emptying it keeps the file, and with it the owner the sync client and other users write as. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B7jPFNJkuXkHhuXsLYLrQw
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.
Closes #814.
Problem
Every whole-file rewrite (the shopping list,
pantry.conf,aisle.conf, recipes saved in the editor, plan edits, pictures, and the references rewritten after a rename) wrote a temporary file and renamed it over the original. The renamed file belongs to whoevercookruns as. On a network share mounted into Docker, that is the share's mount account (dockerin #814), not the owner the files had. The sync client writes these files in place, and afterwards it fails:The CIFS
uid=1000mount option does not help: it only changes the owner the client displays, while the server decides the real one.Fix
cookcli-core'sfs_atomic::write_atomicallyand the server'sfs_atomic::write_replacestill write and flush a temporary file first. When renaming it would hand the file to someone else, they remove the temporary file and overwrite the target in place, which keeps its inode, owner, group and ACL. That covers two cases:statfs).A full disk still fails at the temporary file, before the target is touched. Only a crash during an in-place overwrite can leave a partly written file, the same risk the sync client already takes. Local files with matching ownership are still renamed atomically, as
a_rewrite_never_shortens_the_file_in_placerequires.The editor save, plan edits and picture uploads had their own temp-and-rename code and now go through
write_replace. The editor save therefore also carries permissions over, fsyncs, and no longer leaves a visibleRecipe.tmpbeside the recipe.rename_replace_asynchad no callers left and is removed.Clearing the shopping list now empties
.shopping-checkedinstead of deleting it. A deleted file came back with the next tick as a new file owned by the server's user.libc(already inCargo.lock) is added as a Linux-only dependency of both crates forstatfs.Not changed
auth::write_private_file(session and users files) is meant to be private to the server's account.Testing
cargo fmt,cargo clippy --all-targetsandcargo test --no-fail-fastare clean, except twocookcli-corepantry permission tests that cannot pass as root and fail the same way onmain.tests/e2e/shopping-list*on Chromium: 20 passed, 2 skipped by the specs.cargo build --no-default-features --features server,lsp(the Docker build) compiles.🤖 Generated with Claude Code
https://claude.ai/code/session_01B7jPFNJkuXkHhuXsLYLrQw