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

cp: handle edge cases when dest is a symlink

- Fail if dest is a dangling symlink
- Fail if dest is a symlink that was previously created by the same
invocation of cp
This commit is contained in:
Michael Debertol 2021-08-27 18:40:42 +02:00
parent 8696193b66
commit 3fdff304db
2 changed files with 134 additions and 29 deletions

View file

@ -1368,3 +1368,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'");
}