From a7cb86a3d13b785d76b0f4125d5bb2dcb43a465e Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 4 Oct 2023 15:17:26 +0200 Subject: [PATCH] mv: adapt error message to pass dir2dir.sh --- src/uu/mv/src/mv.rs | 8 +------- tests/by-util/test_mv.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 43f8eb6b651..fd6fa343035 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -399,13 +399,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR match rename(sourcepath, &targetpath, b, multi_progress.as_ref()) { Err(e) if e.to_string().is_empty() => set_exit_code(1), Err(e) => { - let e = e.map_err_context(|| { - format!( - "cannot move {} to {}", - sourcepath.quote(), - targetpath.quote() - ) - }); + let e = e.map_err_context(|| format!("cannot overwrite {}", targetpath.quote())); match multi_progress { Some(ref pb) => pb.suspend(|| show!(e)), None => show!(e), diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index f7f9622f52e..19456e75c74 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1180,6 +1180,32 @@ fn test_mv_overwrite_nonempty_dir() { assert!(at.dir_exists(dir_b)); } +#[test] +fn test_mv_dir_to_nonempty_dir() { + let (at, mut ucmd) = at_and_ucmd!(); + let source = "a/t"; + let destination = "b"; + let file = "b/t/file"; + + at.mkdir_all(source); + at.mkdir_all(&format!("{destination}/t")); + at.touch(file); + + #[cfg(not(windows))] + let expected_msg = "mv: cannot overwrite 'b/t': Directory not empty\n"; + #[cfg(windows)] + let expected_msg = "mv: cannot overwrite 'b\\t': Directory not empty\n"; + + ucmd.arg(source) + .arg(destination) + .fails() + .no_stdout() + .stderr_is(expected_msg); + + assert!(at.dir_exists(source)); + assert!(at.dir_exists(destination)); +} + #[test] fn test_mv_backup_dir() { let (at, mut ucmd) = at_and_ucmd!();