mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
Merge pull request #5430 from cakebaker/cp_remove_destination_shouldnt_fail
cp --remove-destination: don't fail if destination is symlink to source
This commit is contained in:
commit
03d598d08b
2 changed files with 24 additions and 0 deletions
|
@ -1647,6 +1647,14 @@ fn copy_file(
|
|||
dest.display()
|
||||
)));
|
||||
}
|
||||
if paths_refer_to_same_file(source, dest, true)
|
||||
&& matches!(
|
||||
options.overwrite,
|
||||
OverwriteMode::Clobber(ClobberMode::RemoveDestination)
|
||||
)
|
||||
{
|
||||
fs::remove_file(dest)?;
|
||||
}
|
||||
}
|
||||
|
||||
if file_or_link_exists(dest) {
|
||||
|
|
|
@ -2827,6 +2827,22 @@ fn test_cp_mode_hardlink_no_dereference() {
|
|||
assert_eq!(at.read_symlink("z"), "slink");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove_destination_with_destination_being_a_symlink_to_source() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file = "file";
|
||||
let symlink = "symlink";
|
||||
|
||||
at.touch(file);
|
||||
at.symlink_file(file, symlink);
|
||||
|
||||
ucmd.args(&["--remove-destination", file, symlink])
|
||||
.succeeds();
|
||||
assert!(!at.symlink_exists(symlink));
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.file_exists(symlink));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove_destination_symbolic_link_loop() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
Loading…
Reference in a new issue