Skip to content

fix: keep a file's owner when CookCLI rewrites it - #819

Merged
dubadub merged 3 commits into
mainfrom
fix/shopping-list-owner-814
Nov 3, 2026
Merged

dubadub merged 3 commits into
mainfrom
fix/shopping-list-owner-814

Conversation

@dubadub

@dubadub dubadub commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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 whoever cook runs as. On a network share mounted into Docker, that is the share's mount account (docker in #814), not the owner the files had. The sync client writes these files in place, and afterwards it fails:

IoError { path: ".shopping-list", source: Os { code: 13, kind: PermissionDenied } }

The CIFS uid=1000 mount option does not help: it only changes the owner the client displays, while the server decides the real one.

Fix

cookcli-core's fs_atomic::write_atomically and the server's fs_atomic::write_replace still 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:

  • the target's owner or group differs from the temporary file's;
  • the target is on SMB/CIFS or NFS (Linux, 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_place requires.

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 visible Recipe.tmp beside the recipe. rename_replace_async had no callers left and is removed.

Clearing the shopping list now empties .shopping-checked instead of deleting it. A deleted file came back with the next tick as a new file owned by the server's user.

libc (already in Cargo.lock) is added as a Linux-only dependency of both crates for statfs.

Not changed

  • auth::write_private_file (session and users files) is meant to be private to the server's account.

Testing

  • New tests in both crates give a file another owner, rewrite it, and check that the owner and inode stay the same. They need root and skip without it.
  • cargo fmt, cargo clippy --all-targets and cargo test --no-fail-fast are clean, except two cookcli-core pantry permission tests that cannot pass as root and fail the same way on main.
  • Playwright 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.
  • Not tried on a real SMB or NFS mount.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B7jPFNJkuXkHhuXsLYLrQw

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
@claude

claude Bot commented Nov 2, 2026

Copy link
Copy Markdown

Code review

No 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
@dubadub
dubadub merged commit 6f21191 into main Nov 3, 2026
6 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.

Docker - Issue with shoppinglist permissions on mounted folder

2 participants