Skip to content

mv: do not follow a symlink destination when checking it - #15912

Merged
sylvestre merged 3 commits into
uutils:mainfrom
gibkim:mv-dangling-symlink-dest
Nov 29, 2026
Merged

sylvestre merged 3 commits into
uutils:mainfrom
gibkim:mv-dangling-symlink-dest

Conversation

@gibkim

@gibkim gibkim commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

The overwrite guards ran only when the destination resolved, so -n, -i, -u,
--update=none(-fail) and -b were skipped for a dangling symlink, which was
then replaced. The destination is now checked with lstat, and -u and the
overwrite prompt use the link's own mtime and mode, as GNU mv does.

Closes #15778

@codspeed

codspeed Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 8 untouched benchmarks
⏩ 464 skipped benchmarks1


Comparing gibkim:mv-dangling-symlink-dest (69ae0db) with main (c8912fe)

Open in CodSpeed

Footnotes

  1. 464 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

gibkim and others added 3 commits November 1, 2026 18:26
The overwrite guards ran only when the destination resolved, so -n, -i,
-u, --update=none(-fail) and -b were all skipped for a dangling symlink,
which was then replaced. Check the destination entry with lstat instead,
and use the link's own mtime and mode for -u and the overwrite prompt,
as GNU mv does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-u compared the times before the check that a directory can't replace a
non-directory, so moving a directory into a target directory that holds a
newer symlink of the same name was skipped and reported success. Only skip
when the move itself is possible, and compare the source's own times too.
On Windows, look at the symlink itself when checking that the destination is
writable, as on Unix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sylvestre
sylvestre force-pushed the mv-dangling-symlink-dest branch from 53096a7 to 69ae0db Compare November 1, 2026 17:26
@sylvestre
sylvestre merged commit 2a072db into uutils:main Nov 29, 2026
140 of 141 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

sorry for the slow reaction! Thanks for your PR

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: -n, -i, -u and -b ignored when destination is a dangling symlink

2 participants