cp: do not write a recursive copy through a symlinked target - #14993
Open
abendrothj wants to merge 1 commit into
Open
abendrothj wants to merge 1 commit into
abendrothj wants to merge 1 commit into
Conversation
The entry for the target itself was built as `target.join("")`, which
appends a separator, so the symlink check in copy_direntry looked through
a target that is a symlink. `cp -rT src dst` with `dst` a symlink to a
directory then copied into the link's target instead of refusing, and
`cp -r src dst` with `dst` a dangling symlink created the directory it
points at. GNU refuses both.
Keep the target path as given for that entry. `cp -r src/. dst` and a
target written with a trailing slash still copy into what the symlink
resolves to, as GNU does. The verbose line for the top directory now
reads `'src' -> 'dst'` without the slash, also matching GNU.
abendrothj
force-pushed
the
cp-rt-dest-symlink
branch
from
October 1, 2026 01:29
6faa767 to
5066d9b
Compare
|
GNU testsuite comparison: |
This branch has not been deployed
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.
The top-level entry of a recursive copy was built as
target.join(""), which adds a trailing separator, so the symlink check looked through a target that is a symlink.cp -rT src dstwithdsta symlink to a directory copied into the link's target, and a danglingdstgot the directory it points at created.That entry now keeps the target path as given.
cp -r src/. dstanddst/still copy into what the link resolves to, as GNU does. The verbose line for the top directory loses its trailing slash, which also matches GNU, so two verbose tests are updated.Closes #14992