coreutils
coreutils copied to clipboard
cp: symlink overwrite-detection is broken
Steps to reproduce:
- Create two regular files,
README.mdandgood/README.md, and an initially-empty directorytmp/. - Inside
tmp, create an empty regular filefoo, and a symlinkREADME.mdthat points tofoo. - Try to copy
README.mdandgood/README.mdtotmp/
Expected result: README.md is copied to tmp/ into the file foo, and the second attempt is aborted, leading to an error message and a non-zero (failure) exit code.
Actual result: README.md is copied to tmp/ into the file foo, and the second attempt is successful, leading to foo containing the contents of the second file, no error message, and a zero (success) exit code.
Demonstrator:
$ mkdir -p good && cp README.md good/README.md
$ rm -rf tmp/ && mkdir tmp/ && ln -s foo tmp/README.md && touch tmp/foo
$ ../gnu/src/cp README.md good/README.md tmp # Yes error!
../gnu/src/cp: will not copy 'good/README.md' through just-created symlink 'tmp/README.md'
[$? = 1]
$
$ mkdir -p good && cp README.md good/README.md
$ rm -rf tmp/ && mkdir tmp/ && ln -s foo tmp/README.md && touch tmp/foo
$ cargo run cp README.md good/README.md tmp # No error?!
$
Found while reviewing #6208