Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Loading