From 1c8aac0883da366cb47ea7f755d41f2831fb1b9b Mon Sep 17 00:00:00 2001 From: John Shin Date: Wed, 3 May 2023 16:05:21 -0700 Subject: [PATCH 1/2] mv: return err if response is negative when moving a dir to existing dest during an interactive mode --- src/uu/mv/src/mv.rs | 2 +- tests/by-util/test_mv.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 1a7897a91a6..9632ddabf2d 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -292,7 +292,7 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> { OverwriteMode::NoClobber => return Ok(()), OverwriteMode::Interactive => { if !prompt_yes!("overwrite {}? ", target.quote()) { - return Ok(()); + return Err(io::Error::new(io::ErrorKind::Other, "").into()); } } OverwriteMode::Force => {} diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index ce9e26a819e..d61cd45dcf3 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -260,6 +260,27 @@ fn test_mv_interactive_with_dir_as_target() { .no_stdout(); } +#[test] +fn test_mv_interactive_dir_to_file_not_affirmative() { + let (at, mut ucmd) = at_and_ucmd!(); + + let dir = "test_mv_interactive_dir_to_file_not_affirmative_dir"; + let file = "test_mv_interactive_dir_to_file_not_affirmative_file"; + + at.mkdir(dir); + at.touch(file); + + ucmd.arg(dir) + .arg(file) + .arg("-i") + .pipe_in("n") + .fails() + .no_stderr() + .no_stdout(); + + assert!(at.dir_exists(dir)); +} + #[test] fn test_mv_arg_update_interactive() { let (at, mut ucmd) = at_and_ucmd!(); From 84567336a88c4fbe865b2982e82d3e27d444b908 Mon Sep 17 00:00:00 2001 From: John Shin Date: Wed, 3 May 2023 23:54:28 -0700 Subject: [PATCH 2/2] mv: update test case so it doesn't fail --- tests/by-util/test_mv.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index d61cd45dcf3..7ce76832a3b 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -275,7 +275,6 @@ fn test_mv_interactive_dir_to_file_not_affirmative() { .arg("-i") .pipe_in("n") .fails() - .no_stderr() .no_stdout(); assert!(at.dir_exists(dir));