mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
cp: Duplicate source error message specify the type of file.
This commit is contained in:
parent
4d5bf4205f
commit
ff586b47d4
2 changed files with 22 additions and 2 deletions
|
@ -1266,7 +1266,15 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
|
|||
for source in sources {
|
||||
let normalized_source = normalize_path(source);
|
||||
if options.backup == BackupMode::NoBackup && seen_sources.contains(&normalized_source) {
|
||||
show_warning!("source file {} specified more than once", source.quote());
|
||||
let file_type = if source.symlink_metadata()?.file_type().is_dir() {
|
||||
"directory"
|
||||
} else {
|
||||
"file"
|
||||
};
|
||||
show_warning!(
|
||||
"source {file_type} {} specified more than once",
|
||||
source.quote()
|
||||
);
|
||||
} else {
|
||||
let dest = construct_dest_path(source, target, target_type, options)
|
||||
.unwrap_or_else(|_| target.to_path_buf());
|
||||
|
|
|
@ -120,7 +120,19 @@ fn test_cp_duplicate_files() {
|
|||
));
|
||||
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_duplicate_folder() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
ucmd.arg("-r")
|
||||
.arg(TEST_COPY_FROM_FOLDER)
|
||||
.arg(TEST_COPY_FROM_FOLDER)
|
||||
.arg(TEST_COPY_TO_FOLDER)
|
||||
.succeeds()
|
||||
.stderr_contains(format!(
|
||||
"source directory '{TEST_COPY_FROM_FOLDER}' specified more than once"
|
||||
));
|
||||
assert!(at.dir_exists(format!("{TEST_COPY_TO_FOLDER}/{TEST_COPY_FROM_FOLDER}").as_str()));
|
||||
}
|
||||
#[test]
|
||||
fn test_cp_duplicate_files_normalized_path() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue