uutils / coreutils

Cross-platform Rust rewrite of the GNU coreutils

Home Page:https://uutils.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

BenWiederhake opened this issue · comments

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.