mirror of
https://github.com/uutils/coreutils
synced 2024-11-15 01:17:09 +00:00
Merge pull request #3981 from jfinkels/cp-directory-into-itself
cp: correct error message on copying dir to itself
This commit is contained in:
commit
6b36a266e4
2 changed files with 29 additions and 1 deletions
|
@ -1092,7 +1092,7 @@ fn copy_directory(
|
|||
return Err(format!(
|
||||
"cannot copy a directory, {}, into itself, {}",
|
||||
root.quote(),
|
||||
target.quote()
|
||||
target.join(root.file_name().unwrap()).quote()
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
|
|
@ -2095,3 +2095,31 @@ fn test_cp_mode_hardlink_no_dereference() {
|
|||
assert!(at.symlink_exists("z"));
|
||||
assert_eq!(at.read_symlink("z"), "slink");
|
||||
}
|
||||
|
||||
/// Test that copying a directory to itself is disallowed.
|
||||
#[test]
|
||||
fn test_copy_directory_to_itself_disallowed() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("d");
|
||||
#[cfg(not(windows))]
|
||||
let expected = "cp: cannot copy a directory, 'd', into itself, 'd/d'";
|
||||
#[cfg(windows)]
|
||||
let expected = "cp: cannot copy a directory, 'd', into itself, 'd\\d'";
|
||||
ucmd.args(&["-R", "d", "d"]).fails().stderr_only(expected);
|
||||
}
|
||||
|
||||
/// Test that copying a nested directory to itself is disallowed.
|
||||
#[test]
|
||||
fn test_copy_nested_directory_to_itself_disallowed() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("a");
|
||||
at.mkdir("a/b");
|
||||
at.mkdir("a/b/c");
|
||||
#[cfg(not(windows))]
|
||||
let expected = "cp: cannot copy a directory, 'a/b', into itself, 'a/b/c/b'";
|
||||
#[cfg(windows)]
|
||||
let expected = "cp: cannot copy a directory, 'a/b', into itself, 'a/b/c\\b'";
|
||||
ucmd.args(&["-R", "a/b", "a/b/c"])
|
||||
.fails()
|
||||
.stderr_only(expected);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue