-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
When combining the special-cases "copying file to itself" and "symlinks", weird things happen. Currently, about half of the scenarios I tested try something wrong, in one case even succeeding when it shouldn't.
$ ln -s README.md symlink_good
$ ln -s nonexistent symlink_bad
$ cp -vP symlink_good symlink_bad .; echo "[\$? = $?]"; cargo run -q cp -vP symlink_good symlink_bad .; echo "[\$? = $?]"
cp: 'symlink_good' and './symlink_good' are the same file
cp: 'symlink_bad' and './symlink_bad' are the same file
[$? = 1]
'symlink_good' -> './symlink_good'
'symlink_bad' -> './symlink_bad'
[$? = 0]
$ cp -v symlink_good symlink_bad .; echo "[\$? = $?]"; cargo run -q cp -v symlink_good symlink_bad .; echo "[\$? = $?]"
cp: 'symlink_good' and './symlink_good' are the same file
cp: cannot stat 'symlink_bad': No such file or directory
[$? = 1]
cp: 'symlink_good' and './symlink_good' are the same file
cp: not writing through dangling symlink './symlink_bad'
[$? = 1]
$ cp -vs symlink_good symlink_bad .; echo "[\$? = $?]"; cargo run -q cp -vs symlink_good symlink_bad .; echo "[\$? = $?]"
'symlink_good' -> './symlink_good'
cp: cannot create symbolic link './symlink_good' to 'symlink_good': File exists
cp: cannot stat 'symlink_bad': No such file or directory
[$? = 1]
'symlink_good' -> './symlink_good'
cp: cannot create symlink 'symlink_good' to 'symlink_good': File exists (os error 17)
cp: not writing through dangling symlink './symlink_bad'
[$? = 1]
$ cp -vl symlink_good symlink_bad .; echo "[\$? = $?]"; cargo run -q cp -vl symlink_good symlink_bad .; echo "[\$? = $?]"
'symlink_good' -> './symlink_good'
cp: cannot create hard link './symlink_good' to 'symlink_good': File exists
cp: cannot stat 'symlink_bad': No such file or directory
[$? = 1]
'symlink_good' -> './symlink_good'
cp: cannot create hard link 'symlink_good' to 'symlink_good': File exists (os error 17)
cp: not writing through dangling symlink './symlink_bad'
[$? = 1]Found while reviewing #6586.