Open
Conversation
cp -f: Only unlink destination when it cannot be opened for writing. Writable destinations are overwritten in place, preserving hard links and inodes. cp -p: Add fchown call to copyFileWithAttributes to preserve source uid/gid. EPERM silently ignored for non-root. chown -RP: Use lstat instead of stat at chownRecursive entry so a cmdline symlink-to-directory is not followed. chmod -R -P: Skip symlinks during recursive traversal instead of applying chmod through them to the target.
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
-funconditionally unlinked the destination, severing hard links even when unnecessary.fchowncall tocopyFileWithAttributesto preserve source uid/gid on the copy. EPERM is silently ignored for non-root users, matching GNU behavior.lstatinstead ofstatat the entry ofchownRecursivewhen-Pis active (or when neither-Hnor-Lis set). This prevents following a cmdline symlink-to-directory and incorrectly recursing into the target.chmodthrough them to the target file. GNU chmod silently skips symlinks during-R.Test plan
cp: -f should not unlink writable destination (preserves hard links)— creates a hard link to dest, copies with-f, verifies inode preservedcp: -p should preserve group ownership via chown— copies with-p, verifies gid matcheschown -RP should not follow cmdline symlink to directory— creates symlink to dir, runs chown -RP with verbose, verifies target dir contents not in output (skipped without fakeroot)chmod: -R -P should not follow symlinks during traversal— creates symlink to outside file, runs chmod -R -P, verifies outside file mode unchanged