Skip to content

Commit

Permalink
fixup! cp: correct error message on copying dir to itself
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinkels committed Sep 27, 2022
1 parent 7e0399e commit 2ae9cdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ fn copy_directory(
return Err(format!(
"cannot copy a directory, {}, into itself, {}",
root.quote(),
root.join(target).quote()
target.join(root.file_name().unwrap()).quote()
)
.into());
}
Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2089,3 +2089,19 @@ fn test_copy_directory_to_itself_disallowed() {
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);
}

0 comments on commit 2ae9cdb

Please sign in to comment.