Skip to content

Commit

Permalink
mv: Show 'skipped' when a file isn't overwriten
Browse files Browse the repository at this point in the history
Should fix tests/mv/mv-n.sh
  • Loading branch information
sylvestre committed May 27, 2023
1 parent e920d8d commit f604b50
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,21 @@ fn rename(

match b.overwrite {
OverwriteMode::NoClobber => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("not replacing {}", to.quote()),
));
if b.verbose {
println!("skipped {}", to.quote());
return Err(io::Error::new(io::ErrorKind::Other, ""));
} else {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("not replacing {}", to.quote()),
));
}
}
OverwriteMode::Interactive => {
if !prompt_yes!("overwrite {}?", to.quote()) {
if b.verbose {
println!("skipped {}", to.quote());
}
return Err(io::Error::new(io::ErrorKind::Other, ""));
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,29 @@ fn test_mv_info_self() {
.stderr_contains("mv: cannot move 'dir2' to a subdirectory of itself, 'dir2/dir2'");
}

#[test]
fn test_mv_arg_interactive_skipped() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("a");
at.touch("b");
ucmd.args(&["-vi", "a", "b"])
.pipe_in("N\n")
.fails()
.stderr_is("mv: overwrite 'b'? ")
.stdout_is("skipped 'b'\n");
}

#[test]
fn test_mv_arg_interactive_skipped_vin() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("a");
at.touch("b");
ucmd.args(&["-vin", "a", "b"])
.pipe_in("y\n")
.fails()
.stdout_is("skipped 'b'\n");
}

#[test]
fn test_mv_into_self_data() {
let scene = TestScenario::new(util_name!());
Expand Down

0 comments on commit f604b50

Please sign in to comment.