Repository navigation
ln: report same file for any backup mode - #15545
Merged
Merged
Conversation
Priyanshu-choudhary
marked this pull request as ready for review
October 20, 2026 13:56
With --backup=simple or --backup=numbered, linking a file onto itself renamed the destination to its backup before linking, so the link then failed with a misleading "No such file or directory" error. Run the same-file check for every backup mode except none, as was already done for --backup=existing. Fixes uutils#15527
Priyanshu-choudhary
force-pushed
the
ln-backup-same-file
branch
from
October 20, 2026 14:33
40ba37f to
79c5e84
Compare
Contributor
|
Thanks for your PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #15527
Problem
With
--backup=simpleor--backup=numbered, linking a file onto itself gives a misleading error.lnrenames the destination to its backup first, so the source is gone by the time the hard link is created:GNU coreutils 9.12 reports
ln: 'a' and 'a' are the same file. Both exit 1 and leaveaunchanged.The same thing happens without
-f, with--backup=numbered, with./a a, and with a directory target (ln -f --backup=simple d/a d).Fix
link()already detects the same file before backing up, but only for--backup=existing. This PR runs that check for every backup mode exceptnone, since every other mode renames the destination before linking. Symbolic links are still excluded:ln -sf --backup=simple a astays valid and behaves like GNU.Testing
Compared against GNU coreutils 9.12 (LC_ALL=C, Linux):
ln -f --backup=simple a aln -f --backup=numbered a aln --backup=simple a a(no-f)ln -f --backup=numbered ./a aln -f --backup=simple d/a dln -f --backup=simple sl sl(symlink)Unchanged and still matching GNU:
--backup=existing,--backup=none,-f -b a a,ln -sf --backup=simple a a(succeeds, keepsa~), andln -f --backup=simple a bwherebis a hard link toa(succeeds, createsb~).test_backup_simple_numbered_same_fileandtest_backup_simple_same_file_into_directory. Both failed before the fix and pass after it.cargo test --features ln --no-default-features test_ln: 64 passed.cargo fmt --checkandcargo clippy -p uu_ln --all-targets -- -D warningsare clean.