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..7ce76832a3b 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -260,6 +260,26 @@ 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_stdout(); + + assert!(at.dir_exists(dir)); +} + #[test] fn test_mv_arg_update_interactive() { let (at, mut ucmd) = at_and_ucmd!();