Skip to content

mv: allow moving a symlink onto another hard link - #17071

Open
tonycoder-hub wants to merge 1 commit into
uutils:mainfrom
tonycoder-hub:gb/mv-symlink-onto-hardlink
Open

tonycoder-hub wants to merge 1 commit into
uutils:mainfrom
tonycoder-hub:gb/mv-symlink-onto-hardlink

Conversation

@tonycoder-hub

Copy link
Copy Markdown

mv s h refused when s was a symlink to f and h was another hard link of f, reporting that they were the same file and exiting 1. Replacing h only removes one name; the file stays reachable through f, and GNU mv performs this move.

The same-file check now allows the move when the source is a symlink, its canonical path differs from the destination, and the destination has more than one link (counted via uucore::fs::FileInformation::number_of_links, so the symlink is not dereferenced). Moving the symlink onto the name it points at, or onto a file that has only one link, is still refused. Two hard links of the same symlink are still refused by the existing hard-link check.

Closes #17040

Testing

  • New test_mv_symlink_onto_other_hard_link_of_referent fails on main (mv: 's' and 'h' are the same file) and passes with this change.
  • cargo test --no-default-features --features mv --test tests test_mv:: (167 passed)
  • cargo fmt --all -- --check, cargo clippy -p uu_mv --all-targets -- -D warnings, cargo check -p uu_mv --target x86_64-pc-windows-gnu
  • Behavior compared against the installed GNU mv 9.4 binary (no GNU source consulted).

This change was prepared with AI assistance and verified by the tests above.

A symlink and a different hard link of its referent were reported as
the same file, so mv refused a move that only replaces that name and
leaves the file reachable through the remaining links. The name the
symlink points at, and a file with a single link, are still refused.

Signed-off-by: Tony Coder <407243179@qq.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mv refuses to move a symlink onto a hard link of its referent as "the same file", an operation GNU mv has performed since 8.16

1 participant