Repository navigation
fix: preserve directory permissions during copy-ignored step - #1590
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
Permissions must be set after copying contents, not before. If a source directory lacks write permission (e.g., 0o555 or 0o500 — common for read-only caches, vendor dirs), the current code sets the restrictive permissions on dest and then tries to copy files into it, which fails with EACCES.
Move the set_permissions block below the for entry in fs::read_dir(src)? loop.
The test only covers 0o700 (which includes write), so it doesn't catch this.
|
@worktrunk-bot fix tests please |
`copy_dir_recursive_fallback()` used `fs::create_dir_all()` which creates directories with default permissions (0755), ignoring the source directory's permissions. This caused directories with restrictive permissions (e.g., 0700 for a Postgres data directory) to become world-readable in new worktrees. Now copies source directory permissions to the destination after creation. Closes #1589 Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
If the source directory lacks write permission (e.g., 0o555), setting permissions before copying makes the destination read-only and causes file copies to fail with EACCES. Move set_permissions after the loop. Also adds a test case for 0o555 directories and fixes the existing error-path test to not depend on source permissions. Co-Authored-By: Claude <[email protected]>
d664086 to
a6ed0d8
Compare
|
Rebased onto main — the branch was 4 commits behind, which caused snapshot mismatches in 61 tests (mock commands, CI status, switch PR/MR tests). All 1204 integration tests pass locally after rebase. Pushed and waiting for CI. |
|
OK — and is there a way to copy the paths while retaining permissions from the initial copy? I worry this is a patch on an underlying issue... |
|
Good question. For files, On Unix we could use The two-step approach is the standard pattern for recursive copies that preserve permissions — |
Problem
copy_dir_recursive_fallback()usesfs::create_dir_all()to create destination directories, which always uses default permissions (0755). This means source directory permissions are lost during the copy-ignored step.For example, a directory with mode
0700(used by tools like Postgres for data directories) becomes0755in the new worktree, breaking applications that require specific directory permissions.Solution
After creating the destination directory, copy the source directory's permissions using
fs::set_permissions()on Unix. This preserves the original permission mode for all directories copied recursively.Testing
test_copy_ignored_preserves_directory_permissions— creates a directory with mode 0700, copies it via copy-ignored, and verifies the destination has the same modetest_copy_ignored_error_includes_path_directory— the source directory now also has restricted permissions so that the permission-preservation code maintains the error scenarioCloses #1589 — automated triage