Skip to content

Commit 2c528cf

Browse files
committed
mv: fix error message when one of the multiple src doesn't exist
1 parent e947c71 commit 2c528cf

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/uu/mv/src/mv.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options)
446446
};
447447

448448
for sourcepath in files {
449+
if !sourcepath.exists() {
450+
show!(MvError::NoSuchFile(sourcepath.quote().to_string()));
451+
continue;
452+
}
453+
449454
if let Some(ref pb) = count_progress {
450455
pb.set_message(sourcepath.to_string_lossy().to_string());
451456
}

tests/by-util/test_mv.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,3 +1717,18 @@ mod inter_partition_copying {
17171717
.stderr_contains("Permission denied");
17181718
}
17191719
}
1720+
1721+
#[test]
1722+
fn test_mv_error_msg_with_multiple_sources_that_does_not_exist() {
1723+
let scene = TestScenario::new(util_name!());
1724+
let at = &scene.fixtures;
1725+
at.mkdir("d");
1726+
scene
1727+
.ucmd()
1728+
.arg("a")
1729+
.arg("b/")
1730+
.arg("d")
1731+
.fails()
1732+
.stderr_contains("mv: cannot stat 'a': No such file or directory")
1733+
.stderr_contains("mv: cannot stat 'b/': No such file or directory");
1734+
}

0 commit comments

Comments
 (0)