coreutils
coreutils copied to clipboard
mv: show "same file" error for `mv d/f d`
When using mv d/f d
, GNU mv
fails with a "same file" error whereas uutils mv
doesn't fail. This PR makes uutils mv
fail, too.
I wonder if this is the right fix. GNU mv
fails at moving t/a
into u/b
if u/b
exist and is the same file as t/a
(hard link), while your patch seems to compare parents.
Reproducer:
$ mkdir t u
$ touch t/a
$ ln t/a u/a
$ mv t/a u
mv: 't/a' and 'u/a' are the same file
With your patch:
$ […]/target/debug/coreutils mv t/a u
[success]
Thanks for your feedback. I didn't consider hard links when creating this PR :|
I think you can reuse/move around most of the code just before your patch. IIRC, it checks for hardlink equivalence when the target is a file, so if you build the target file name in case you get a directory I guess you might use the same check.