coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

mv: show "same file" error for `mv d/f d`

Open cakebaker opened this issue 5 months ago • 3 comments

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.

cakebaker avatar Jan 05 '24 10:01 cakebaker

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]

samueltardieu avatar Jan 05 '24 11:01 samueltardieu

Thanks for your feedback. I didn't consider hard links when creating this PR :|

cakebaker avatar Jan 05 '24 14:01 cakebaker

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.

samueltardieu avatar Jan 05 '24 16:01 samueltardieu