diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 90f4cb538..cce042bfa 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -9,6 +9,7 @@ use std::cmp::Ordering; use std::collections::{HashMap, HashSet}; #[cfg(not(windows))] use std::ffi::CString; +use std::ffi::OsString; use std::fs::{self, File, Metadata, OpenOptions, Permissions}; use std::io; #[cfg(unix)] @@ -677,7 +678,7 @@ pub fn uu_app() -> Command { Arg::new(options::PATHS) .action(ArgAction::Append) .value_hint(clap::ValueHint::AnyPath) - .value_parser(ValueParser::path_buf()), + .value_parser(ValueParser::os_string()), ) } @@ -707,8 +708,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } let paths: Vec = matches - .remove_many::(options::PATHS) - .map(|v| v.collect()) + .remove_many::(options::PATHS) + .map(|v| v.map(PathBuf::from).collect()) .unwrap_or_default(); let (sources, target) = parse_path_args(paths, &options)?; diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 8781bab3c..290c49f3b 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -54,7 +54,6 @@ static TEST_MOUNT_COPY_FROM_FOLDER: &str = "dir_with_mount"; static TEST_MOUNT_MOUNTPOINT: &str = "mount"; #[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))] static TEST_MOUNT_OTHER_FILESYSTEM_FILE: &str = "mount/DO_NOT_copy_me.txt"; -#[cfg(unix)] static TEST_NONEXISTENT_FILE: &str = "nonexistent_file.txt"; #[cfg(all( unix, @@ -169,6 +168,32 @@ fn test_cp_multiple_files() { assert_eq!(at.read(TEST_HOW_ARE_YOU_DEST), "How are you?\n"); } +#[test] +fn test_cp_multiple_files_with_nonexistent_file() { + let (at, mut ucmd) = at_and_ucmd!(); + ucmd.arg(TEST_HELLO_WORLD_SOURCE) + .arg(TEST_NONEXISTENT_FILE) + .arg(TEST_HOW_ARE_YOU_SOURCE) + .arg(TEST_COPY_TO_FOLDER) + .fails(); + + assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); + assert_eq!(at.read(TEST_HOW_ARE_YOU_DEST), "How are you?\n"); +} + +#[test] +fn test_cp_multiple_files_with_empty_file_name() { + let (at, mut ucmd) = at_and_ucmd!(); + ucmd.arg(TEST_HELLO_WORLD_SOURCE) + .arg("") + .arg(TEST_HOW_ARE_YOU_SOURCE) + .arg(TEST_COPY_TO_FOLDER) + .fails(); + + assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n"); + assert_eq!(at.read(TEST_HOW_ARE_YOU_DEST), "How are you?\n"); +} + #[test] // FixME: for MacOS, this has intermittent failures; track repair progress at GH:uutils/coreutils/issues/1590 #[cfg(not(target_os = "macos"))]