coreutils
coreutils copied to clipboard
cp should raise error when directory specified with trailing / does not exist
If only one source is specified, cp should raise an error when target directory specified with trailing / does not exist. Instead it currently creates a file, as if specified without /. When multiple sources are specified an error is raised.
It's better to always assume that a trailing slash indicates an incorrect directory. It's more in line with other implementations. It's more consistent / less surprising.
$ ls d
ls: cannot access 'd': No such file or directory
$ touch t
$ cp t d/
$ ls d
d
$ touch f
$ cp t f d2/
cp: target: 'd2/' is not a directory
The similar issue is when d is a symlink to a regular file.
$ echo "sample" > a
$ echo "hello" > t
$ cat a
sample
$ cat t
hello
$ ln -s a d
$ cp t d/
$ cat a
hello
Seems that other utilities that use canonicalize also handle trailing slashes not in the way GNU does handle them. For instance, the following usage of realpath fails when running GNU version, and succeeds for uutils. I chose an example with the behavior that is explicitly stated in the GNU documentation that it should fail.
$ touch a
$ ln -s a d
$ realpath -e d/
I want to work on the trailing slashes issue.
Closing this ticket as it seems like the issues have been fixed in the meantime and errors are shown when running the examples.