Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cp: Should refuse to create broken symlinks to parent-dir #6385

Open
BenWiederhake opened this issue May 8, 2024 · 0 comments · May be fixed by #6464
Open

cp: Should refuse to create broken symlinks to parent-dir #6385

BenWiederhake opened this issue May 8, 2024 · 0 comments · May be fixed by #6464
Labels

Comments

@BenWiederhake
Copy link
Collaborator

Copying files as symbolic links to a new (sub-)directory would require constructing a relative path from the new location to the old, e.g. starting with ../.

Trying to do so would necessarily be very fragile. GNU cp even refuses to attempt it. However, uutils currently does it, very badly, resulting in completely broken links and exit code 0.

$ mkdir newdir  
$ cp -vs README.md newdir/  # GNU refuses to create broken symbolic links
'README.md' -> 'newdir/README.md'
cp: newdir/README.md: can make relative symbolic links only in current directory
[$? = 1]
$ ls newdir/  # It's empty
$ cargo run -q cp -vs README.md newdir/  # uutils returns "success"
'README.md' -> 'newdir/README.md'
$ ls newdir/  # And creates something
README.md
$ readlink newdir/README.md  # It creates a self-link
README.md
$ less newdir/README.md 
newdir/README.md: Too many levels of symbolic links
[$? = 1]

Discovered while reviewing #6380.

@luigieli luigieli linked a pull request Jun 13, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant