mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #2610 from miDeb/cp/abuse
cp: handle edge cases when dest is a symlink
This commit is contained in:
commit
f60c36f242
7 changed files with 263 additions and 56 deletions
|
@ -1379,3 +1379,42 @@ fn test_canonicalize_symlink() {
|
|||
.no_stderr()
|
||||
.no_stdout();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_copy_through_just_created_symlink() {
|
||||
for &create_t in &[true, false] {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("a");
|
||||
at.mkdir("b");
|
||||
at.mkdir("c");
|
||||
#[cfg(unix)]
|
||||
fs::symlink("../t", at.plus("a/1")).unwrap();
|
||||
#[cfg(target_os = "windows")]
|
||||
symlink_file("../t", at.plus("a/1")).unwrap();
|
||||
at.touch("b/1");
|
||||
if create_t {
|
||||
at.touch("t");
|
||||
}
|
||||
ucmd.arg("--no-dereference")
|
||||
.arg("a/1")
|
||||
.arg("b/1")
|
||||
.arg("c")
|
||||
.fails()
|
||||
.stderr_only(if cfg!(not(target_os = "windows")) {
|
||||
"cp: will not copy 'b/1' through just-created symlink 'c/1'"
|
||||
} else {
|
||||
"cp: will not copy 'b/1' through just-created symlink 'c\\1'"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_copy_through_dangling_symlink() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch("file");
|
||||
at.symlink_file("nonexistent", "target");
|
||||
ucmd.arg("file")
|
||||
.arg("target")
|
||||
.fails()
|
||||
.stderr_only("cp: not writing through dangling symlink 'target'");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue