1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 05:27:45 +00:00

Merge pull request #5253 from dmatos2012/cp_source_error

cp: Error out if cp only contains source
This commit is contained in:
Daniel Hofstetter 2023-09-06 07:40:48 +02:00 committed by GitHub
commit 1adca622e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -1073,6 +1073,9 @@ fn parse_path_args(
if paths.is_empty() {
// No files specified
return Err("missing file operand".into());
} else if paths.len() == 1 && options.target_dir.is_none() {
// Only one file specified
return Err(format!("missing destination file operand after {:?}", paths[0]).into());
}
// Return an error if the user requested to copy more than one

View file

@ -3231,3 +3231,15 @@ fn test_cp_debug_sparse_always_reflink_auto() {
panic!("Failure: stdout was \n{stdout_str}");
}
}
#[test]
fn test_cp_only_source_no_target() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
at.touch("a");
let result = ts.ucmd().arg("a").fails();
let stderr_str = result.stderr_str();
if !stderr_str.contains("missing destination file operand after \"a\"") {
panic!("Failure: stderr was \n{stderr_str}");
}
}