mv hardlinks should be preserved when moving into a different directory
Testcase:
export C=/usr/bin/
export C="target/debug/coreutils "
dir=hlink
other_partition_tmpdir=/dev/shm/tmp769306
rm -rf $dir $other_partition_tmpdir
mkdir $dir $other_partition_tmpdir
> $dir/a
ln $dir/a $dir/b
${C}mv $dir "$other_partition_tmpdir"
ls -1i "$other_partition_tmpdir/$dir"
They should be equal. They aren't currently
I've try to reproduce this:
❯ mkdir test
❯ mkdir test2
❯ > test/a
❯ ln test/a test/b
❯ target/release-small/coreutils mv test test2
❯ ls -1i test2/test/
4219332 a
4219332 b
Does your test only work when moving the folder to another partition?
That's very likely, mv can't do a simple rename across partitions, so it has some fallback procedure that's probably not working as expected here.
Ok thanks for your input, I will try to reproduce this with an USB key.
EDIT: I got the test working, I will try to fix this then
I've tracked down the issue to move_dir here. But this function comes from webdesus/fs_extra so I will have a look there
There is a similar issue for symlink and a PR was proposed without reaction from the author. I wonder if we should "just" implement it directly on our side...
I've try to reproduce this:
❯ mkdir test ❯ mkdir test2 ❯ > test/a ❯ ln test/a test/b ❯ target/release-small/coreutils mv test test2 ❯ ls -1i test2/test/ 4219332 a 4219332 bDoes your test only work when moving the folder to another partition?
Why do I get an error when trying to move the test into test2, but it is OKAY when using GNU mv?
nemesis@nemesis:~/Documents/Github/test/bin_3$ /home/nemesis/Documents/Github/Focus/util/coreutils_master/target/release/coreutils mv test test2
mv: cannot move 'test' to a subdirectory of itself, 'test2/test'
@allaboutevemirolive it's a bug, I opened a ticket for it: https://github.com/uutils/coreutils/issues/5481
There is a similar issue for symlink and a PR was proposed without reaction from the author. I wonder if we should "just" implement it directly on our side...
I guess this is probably not a good first issue anymore then, as it involves a project management decision. Perhaps the label should be dropped or at least direction about how to proceed with this provided.
Also, fs_extra's maintainer seems to have little time for continuing the project. Could that become a problem as uutils keeps expanding?
There is a similar issue for symlink and a PR was proposed without reaction from the author. I wonder if we should "just" implement it directly on our side...
That project is abandoned fully, so either someone has to fork and maintain it or uutils can just write an implementation.
This looks fixed on main by #8296, which wasn't linked here so the issue stayed open.
Re-ran the testcase on current main (f2855f0), moving a directory from ext4 /tmp to tmpfs /dev/shm with a, b and sub/c hardlinked:
dir/a ino=1618 nlink=3
dir/b ino=1618 nlink=3
dir/sub/c ino=1618 nlink=3
Same result as GNU mv 9.7. Moving two hardlinked files in one call also keeps them on one inode. mv no longer goes through fs_extra for this; the cross-device path uses hardlink.rs, and test_mv_preserves_hardlinks_across_partitions and the related tests in inter_partition_copying cover it.
I think this can be closed, and the good first issue label is probably no longer accurate.
Correction to my earlier comment: the cross-device fix on main only covers moving into an existing directory. Tested on Linux x86_64, main e0c703b0e, /tmp (ext4) to /dev/shm (tmpfs), with d/a, d/b and d/s/c hard-linked:
mv d /dev/shm/x/: links kept (one inode), same as GNU 9.12.mv d /dev/shm/x/new:a,bands/cend up as three files with nlink=1.mv -T d /dev/shm/x/new: same split.
GNU 9.12 keeps one inode in all three cases. #16125 fixes the two renaming forms on the same setup.