mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
cp: don't fail when --backup=numbered is passed
This commit is contained in:
parent
837640bc02
commit
06c98fbdd3
2 changed files with 16 additions and 3 deletions
|
@ -1203,7 +1203,9 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
|
|||
if fs::metadata(&dest).is_ok() && !fs::symlink_metadata(&dest)?.file_type().is_symlink()
|
||||
{
|
||||
// There is already a file and it isn't a symlink (managed in a different place)
|
||||
if copied_destinations.contains(&dest) {
|
||||
if copied_destinations.contains(&dest)
|
||||
&& options.backup != BackupMode::NumberedBackup
|
||||
{
|
||||
// If the target file was already created in this cp call, do not overwrite
|
||||
return Err(Error::Error(format!(
|
||||
"will not overwrite just-created '{}' with '{}'",
|
||||
|
|
|
@ -3562,7 +3562,8 @@ fn test_cp_attributes_only() {
|
|||
|
||||
#[test]
|
||||
fn test_cp_seen_file() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir("a");
|
||||
at.mkdir("b");
|
||||
|
@ -3570,11 +3571,21 @@ fn test_cp_seen_file() {
|
|||
at.write("a/f", "a");
|
||||
at.write("b/f", "b");
|
||||
|
||||
ucmd.arg("a/f")
|
||||
ts.ucmd()
|
||||
.arg("a/f")
|
||||
.arg("b/f")
|
||||
.arg("c")
|
||||
.fails()
|
||||
.stderr_contains("will not overwrite just-created 'c/f' with 'b/f'");
|
||||
|
||||
assert!(at.plus("c").join("f").exists());
|
||||
|
||||
ts.ucmd()
|
||||
.arg("--backup=numbered")
|
||||
.arg("a/f")
|
||||
.arg("b/f")
|
||||
.arg("c")
|
||||
.succeeds();
|
||||
assert!(at.plus("c").join("f").exists());
|
||||
assert!(at.plus("c").join("f.~1~").exists());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue