mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Merge pull request #5757 from cakebaker/cp_show_same_file_error
cp: show error if source and destination are same file
This commit is contained in:
commit
cbf42189a2
2 changed files with 15 additions and 0 deletions
|
@ -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(());
|
||||
}
|
||||
|
|
|
@ -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!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue