mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cp: only allow directory for -t
This commit is contained in:
committed by
Sylvestre Ledru
parent
d6c1b7fa91
commit
efd627bb20
@@ -315,6 +315,12 @@ pub fn uu_app<'a>() -> App<'a> {
|
||||
.long(options::TARGET_DIRECTORY)
|
||||
.value_name(options::TARGET_DIRECTORY)
|
||||
.takes_value(true)
|
||||
.validator(|s| {
|
||||
if Path::new(s).is_dir() {
|
||||
return Ok(());
|
||||
}
|
||||
Err("must specify a directory")
|
||||
})
|
||||
.help("copy all SOURCE arguments into target-directory"))
|
||||
.arg(Arg::new(options::NO_TARGET_DIRECTORY)
|
||||
.short('T')
|
||||
|
||||
@@ -183,6 +183,16 @@ fn test_cp_arg_no_target_directory() {
|
||||
.stderr_contains("cannot overwrite directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_target_directory_is_file() {
|
||||
new_ucmd!()
|
||||
.arg("-t")
|
||||
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.fails()
|
||||
.stderr_contains("must specify a directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_interactive() {
|
||||
new_ucmd!()
|
||||
|
||||
Reference in New Issue
Block a user