mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
cp: treat an empty file name as a non-existing file
This commit is contained in:
parent
22401f827b
commit
dd9e7ad363
2 changed files with 30 additions and 4 deletions
|
@ -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<PathBuf> = matches
|
||||
.remove_many::<PathBuf>(options::PATHS)
|
||||
.map(|v| v.collect())
|
||||
.remove_many::<OsString>(options::PATHS)
|
||||
.map(|v| v.map(PathBuf::from).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
let (sources, target) = parse_path_args(paths, &options)?;
|
||||
|
|
|
@ -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"))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue