From c94773f522bdaa5f9c01b9242e912ad8af885605 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 23 Dec 2023 13:27:00 +0100 Subject: [PATCH] mv: make sure it continues when hiting an error --- src/uu/mv/src/mv.rs | 3 ++- tests/by-util/test_mv.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 058532851..ff5aaf93d 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -478,7 +478,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) if moved_destinations.contains(&targetpath) && options.backup != BackupMode::NumberedBackup { // If the target file was already created in this mv call, do not overwrite - return Err(USimpleError::new( + show!(USimpleError::new( 1, format!( "will not overwrite just-created '{}' with '{}'", @@ -486,6 +486,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options) sourcepath.display() ), )); + continue; } // Check if we have mv dir1 dir2 dir2 diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 2e2dc3d81..bc75ada3f 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -1495,6 +1495,32 @@ fn test_mv_seen_file() { assert!(!at.plus("a").join("f").exists()); } +#[test] +fn test_mv_seen_multiple_files_to_directory() { + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + + at.mkdir("a"); + at.mkdir("b"); + at.mkdir("c"); + at.write("a/f", "a"); + at.write("b/f", "b"); + at.write("b/g", "g"); + + ts.ucmd() + .arg("a/f") + .arg("b/f") + .arg("b/g") + .arg("c") + .fails() + .stderr_contains("will not overwrite just-created 'c/f' with 'b/f'"); + assert!(!at.plus("a").join("f").exists()); + assert!(at.plus("b").join("f").exists()); + assert!(!at.plus("b").join("g").exists()); + assert!(at.plus("c").join("f").exists()); + assert!(at.plus("c").join("g").exists()); +} + #[test] fn test_mv_dir_into_file_where_both_are_files() { let scene = TestScenario::new(util_name!());