Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mv: -i -n should have different behavior than -n -i if target exists #4795

Closed
cakebaker opened this issue Apr 27, 2023 · 1 comment · Fixed by #4826
Closed

mv: -i -n should have different behavior than -n -i if target exists #4795

cakebaker opened this issue Apr 27, 2023 · 1 comment · Fixed by #4826
Labels

Comments

@cakebaker
Copy link
Contributor

When using both -i/--interactive and -n/--no-clobber, GNU mv only uses the argument that comes last if the target exists.

$ touch aa.txt
$ touch bb.txt
$ mv aa.txt bb.txt -i -n  # ignores -i
mv: not replacing 'bb.txt'
$ mv aa.txt bb.txt -n -i  # ignores -n
mv: overwrite 'bb.txt'?

With uutils mv, -n/--no-clobber "wins" in both cases:

$ touch aa.txt
$ touch bb.txt
$ cargo run mv aa.txt bb.txt -i -n
mv: not replacing 'bb.txt'
$ cargo run mv aa.txt bb.txt -n -i
mv: not replacing 'bb.txt'
@shinhs0506
Copy link
Contributor

Looks like we just default to -n

fn determine_overwrite_mode(matches: &ArgMatches) -> OverwriteMode {
// This does not exactly match the GNU implementation:
// The GNU mv defaults to Force, but if more than one of the
// overwrite options are supplied, only the last takes effect.
// To default to no-clobber in that situation seems safer:
//
if matches.get_flag(OPT_NO_CLOBBER) {
OverwriteMode::NoClobber
} else if matches.get_flag(OPT_INTERACTIVE) {
OverwriteMode::Interactive
} else {
OverwriteMode::Force
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants