Repository navigation
cp: don't change the source's mode with --link - #15088
Merged
Merged
Conversation
After creating a hard link, cp -l still ran the final chmod meant for newly copied files on the destination. Since the link shares the source's inode, this changed the mode of the source file: under umask 077 a 755 source became 700, and with -f over an existing file the source took the old destination's mode. GNU cp leaves the linked file untouched. Skip that chmod in link mode.
|
GNU testsuite comparison: |
This was referenced Oct 5, 2026
Ariakage
added a commit
to Ariakage/nushell
that referenced
this pull request
Nov 17, 2026
- Reject `-l` together with `-u`: uu_cp 0.12.0 ignores UpdateMode in Link copy mode and IfOlder disables overwrite verification, so the combination silently did the wrong thing. Return IncompatibleParameters instead. - Follow symlinks when linking recursively, matching uutils' resolve_dereference (`!recursive || is_link`); `-P` keeps linking the links themselves. Documented in the flag's help text. - Replace inode/file-index assertions with a portable write-through hard-link check: std's Windows MetadataExt::file_index is unstable and would break the tests target on Windows. - Replace the directory-error test, which never exercised `-l`, with an existing-destination case, a `-lu` rejection test, and a recursive test covering a symlink in the tree. Add an ignored unix-only regression test for the source-mode chmod bug (uutils/coreutils#15087); unignore once a uu_cp release containing uutils/coreutils#15088 is available.
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 #15087
After creating the hard link,
cp -lstill ran the final chmod meant for newly copied files. Because the link shares the source's inode, this changed the mode of the source file. GNU leaves the linked file untouched.This skips that chmod in link mode. Directories created by
cp -rlare handled elsewhere and keep their current behaviour.Checked against GNU coreutils 9.12 for
cp -lunder umask 077 and 022,-lfand-l --backupover an existing file,-lp,-la,-l --no-preserve=modeandcp -rl; source and destination modes and timestamps now match GNU in all cases. Addedtest_cp_arg_link_keeps_source_mode, which fails without the change.