mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-21 12:41:13 +00:00
Merge pull request #3033 from water-ghosts/cp-lb
cp: Create backup before hardlink
This commit is contained in:
commit
37a0a74c19
2 changed files with 23 additions and 0 deletions
|
|
@ -1327,6 +1327,15 @@ fn copy_file(
|
|||
|
||||
match options.copy_mode {
|
||||
CopyMode::Link => {
|
||||
if dest.exists() {
|
||||
let backup_path =
|
||||
backup_control::get_backup_path(options.backup, &dest, &options.backup_suffix);
|
||||
if let Some(backup_path) = backup_path {
|
||||
backup_dest(&dest, &backup_path)?;
|
||||
fs::remove_file(&dest)?;
|
||||
}
|
||||
}
|
||||
|
||||
fs::hard_link(&source, &dest).context(context)?;
|
||||
}
|
||||
CopyMode::Copy => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue