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 388e728
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,19 @@ fn rename(

match b.overwrite {
OverwriteMode::NoClobber => {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("not replacing {}", to.quote()),
));
let err_msg = if b.verbose {
println!("skipped {}", to.quote());
"".to_string()

Check failure on line 445 in src/uu/mv/src/mv.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (macos-12, unix)

ERROR: `cargo clippy`: empty String is being created manually (file:'src/uu/mv/src/mv.rs', line:445)
} else {
format!("not replacing {}", to.quote())
};
return Err(io::Error::new(io::ErrorKind::Other, err_msg));
}
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 388e728

Please sign in to comment.