mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
cp: backup dest symlink linking to source
This commit is contained in:
parent
89fd26c9db
commit
2c42623b6e
2 changed files with 20 additions and 0 deletions
|
@ -1521,6 +1521,7 @@ fn is_forbidden_copy_to_same_file(
|
|||
options.dereference(source_in_command_line) || !source.is_symlink();
|
||||
paths_refer_to_same_file(source, dest, dereference_to_compare)
|
||||
&& !(options.force() && options.backup != BackupMode::NoBackup)
|
||||
&& !(dest.is_symlink() && options.backup != BackupMode::NoBackup)
|
||||
}
|
||||
|
||||
/// Back up, remove, or leave intact the destination file, depending on the options.
|
||||
|
|
|
@ -701,6 +701,25 @@ fn test_cp_arg_backup_with_dest_a_symlink() {
|
|||
assert_eq!(original, at.resolve_link(backup));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_backup_with_dest_a_symlink_to_source() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let source = "source";
|
||||
let source_content = "content";
|
||||
let symlink = "symlink";
|
||||
let backup = "symlink~";
|
||||
|
||||
at.write(source, source_content);
|
||||
at.symlink_file(source, symlink);
|
||||
|
||||
ucmd.arg("-b").arg(source).arg(symlink).succeeds();
|
||||
|
||||
assert!(!at.symlink_exists(symlink));
|
||||
assert_eq!(source_content, at.read(symlink));
|
||||
assert!(at.symlink_exists(backup));
|
||||
assert_eq!(source, at.resolve_link(backup));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_arg_backup_with_other_args() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue