diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 164ecd31f00..73da0af8ea4 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -835,12 +835,22 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let (sources, target) = parse_path_args(paths, &options)?; if let Err(error) = copy(&sources, &target, &options) { - if let CpError::NotAllFilesCopied = error { - // Error::NotAllFilesCopied is non-fatal, but the error - // code should still be EXIT_ERR as does GNU cp - } else { - // Else we caught a fatal bubbled-up error, log it to stderr - show_error!("{error}"); + match error { + CpError::NotAllFilesCopied => { + // non-fatal; exit code still EXIT_ERR + } + CpError::IoErr(io_err) if io_err.kind() == io::ErrorKind::NotFound => { + show_error!( + "{}", + translate!( + "cp-error-cannot-stat", + "source" => format!("'{}'", sources[0].display()) + ) + ); + } + _ => { + show_error!("{error}"); + } } set_exit_code(EXIT_ERR); } diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 6dc5ed61a62..6c24370c6ee 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -8067,3 +8067,13 @@ fn test_cp_p_preserves_posix_acls() { "cp -p must preserve POSIX ACLs (GNU tests/cp/acl regression)", ); } + +#[test] +fn test_progressbar_inexistent_source() { + let (_, mut ucmd) = at_and_ucmd!(); + ucmd.arg("-g") + .arg("inexistent1") + .arg("inexistent2") + .fails_with_code(1) + .stderr_contains("cp: cannot stat 'inexistent1': No such file or directory"); +}