uucore: fall back to '~' when the backup suffix is empty#13274
Open
Adel-Ayoub wants to merge 1 commit into
Open
uucore: fall back to '~' when the backup suffix is empty#13274Adel-Ayoub wants to merge 1 commit into
Adel-Ayoub wants to merge 1 commit into
Conversation
GNU coreutils treats an empty backup suffix as unset and falls back to the default '~'. determine_backup_suffix returned the empty string instead, so --backup combined with an empty --suffix= (or SIMPLE_BACKUP_SUFFIX=) produced a backup path equal to the destination: cp, install and mv silently skipped the backup, and ln failed outright with "Already exists". Fall back to the default suffix when the resolved suffix is empty, the same way a suffix containing a slash is already handled. This is the single shared spot used by cp, install, ln and mv. Fixes uutils#13168
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.
Problem
GNU coreutils treats an empty backup suffix as "unset" and falls back to the
default
~. Ourdetermine_backup_suffix()returned the empty string instead,so with
--backupand an empty--suffix=(orSIMPLE_BACKUP_SUFFIX=) thebackup path became identical to the destination. As a result
cp,installand
mvsilently created no backup, andlnfailed outright.Reported in #13168.
Before / after (vs GNU coreutils 9.11,
LANG=C)cp --backup a b --suffix=b~(old)b~(old)install --backup a b --suffix=b~(old)b~(old)mv --backup --suffix= a bb~(old)b~(old)ln --backup --suffix= a bb~+ linkfailed to create hard link 'a' => 'b': Already exists(exit 1)b~+ linkThe precedence
--suffix>SIMPLE_BACKUP_SUFFIX>~was already correct;only the empty-suffix fallback was missing.
Fix
determine_backup_suffix()already maps a suffix containing/to the default~. Extend that check to also cover the empty suffix, at the single sharedlocation used by
cp,install,lnandmv.Tests
uucore:test_suffix_empty_defaults_to_tildecp:test_cp_arg_suffix_empty_defaults_to_tildeinstall:test_install_backup_empty_suffix_defaults_to_tildeln:test_ln_backup_empty_suffix_defaults_to_tilde(covers the case that previously failed outright)Note: the issue also mentions
--backup=nil; that part is not a bug (nilisthe alias for
existing, and both GNU and uutils already create the backup),so this PR only addresses the empty-suffix case.
Fixes #13168