From d38797bb5032ba96aad0fb2c1bf62a5f2ee2901e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 26 May 2023 18:53:30 +0200 Subject: [PATCH] mv: Show 'skipped' when a file isn't overwriten Should fix tests/mv/mv-n.sh --- src/uu/mv/src/mv.rs | 14 ++++++++++---- tests/by-util/test_mv.rs | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 831b362ae7..5ca677c696 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -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()); + String::new() + } 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, "")); } } diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 39eaed1e72..f73d3249d4 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -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") + .ignore_stdin_write_error() + .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"]) + .fails() + .stdout_is("skipped 'b'\n"); +} + #[test] fn test_mv_into_self_data() { let scene = TestScenario::new(util_name!());