mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cp: always delete the destination for symlinks
This commit is contained in:
parent
6400cded54
commit
9fb927aa85
2 changed files with 18 additions and 0 deletions
|
@ -1269,6 +1269,11 @@ fn copy_link(source: &Path, dest: &Path) -> CopyResult<()> {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// we always need to remove the file to be able to create a symlink,
|
||||||
|
// even if it is writeable.
|
||||||
|
if dest.exists() {
|
||||||
|
fs::remove_file(dest)?;
|
||||||
|
}
|
||||||
dest.into()
|
dest.into()
|
||||||
};
|
};
|
||||||
symlink_file(&link, &dest, &*context_for(&link, &dest))
|
symlink_file(&link, &dest, &*context_for(&link, &dest))
|
||||||
|
|
|
@ -1325,3 +1325,16 @@ fn test_copy_dir_with_symlinks() {
|
||||||
ucmd.args(&["-r", "dir", "copy"]).succeeds();
|
ucmd.args(&["-r", "dir", "copy"]).succeeds();
|
||||||
assert_eq!(at.resolve_link("copy/file-link"), "file");
|
assert_eq!(at.resolve_link("copy/file-link"), "file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
fn test_copy_symlink_force() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.touch("file");
|
||||||
|
at.symlink_file("file", "file-link");
|
||||||
|
at.touch("copy");
|
||||||
|
|
||||||
|
ucmd.args(&["file-link", "copy", "-f", "--no-dereference"])
|
||||||
|
.succeeds();
|
||||||
|
assert_eq!(at.resolve_link("copy"), "file");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue