1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

cp: show error if source & dest are same file

This commit is contained in:
Daniel Hofstetter 2023-12-31 16:01:34 +01:00
parent 89fd26c9db
commit 5673f32c63
2 changed files with 15 additions and 0 deletions

View file

@ -1713,6 +1713,7 @@ fn copy_file(
if are_hardlinks_to_same_file(source, dest)
&& !options.force()
&& options.backup == BackupMode::NoBackup
&& source != dest
{
return Ok(());
}

View file

@ -117,6 +117,20 @@ fn test_cp_duplicate_files() {
assert_eq!(at.read(TEST_COPY_TO_FOLDER_FILE), "Hello, World!\n");
}
#[test]
fn test_cp_same_file() {
let (at, mut ucmd) = at_and_ucmd!();
let file = "a";
at.touch(file);
ucmd.arg(file)
.arg(file)
.fails()
.code_is(1)
.stderr_contains(format!("'{file}' and '{file}' are the same file"));
}
#[test]
fn test_cp_multiple_files_target_is_file() {
new_ucmd!()