1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

cp: fix update prompting (#7668)

* added logic to check if we are updating the file and the destination is newer, to skip copying

* corrected logic to handle cp update

* - added test case that mocks the issue described in #7660
- adjusted conditions to satisfy clippy

* typo

* Update src/uu/cp/src/cp.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Update tests/by-util/test_cp.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
hz2 2025-04-10 10:00:39 -07:00 committed by GitHub
parent 45c978fae6
commit cd2b56ea9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -1828,6 +1828,13 @@ fn handle_existing_dest(
return Err(format!("{} and {} are the same file", source.quote(), dest.quote()).into());
}
if options.update == UpdateMode::ReplaceNone {
if options.debug {
println!("skipped {}", dest.quote());
}
return Err(Error::Skipped(false));
}
if options.update != UpdateMode::ReplaceIfOlder {
options.overwrite.verify(dest, options.debug)?;
}

View file

@ -6167,3 +6167,20 @@ fn test_cp_update_older_interactive_prompt_no() {
.fails()
.stdout_is("cp: overwrite 'old'? ");
}
#[test]
fn test_cp_update_none_interactive_prompt_no() {
let (at, mut ucmd) = at_and_ucmd!();
let old_file = "old";
let new_file = "new";
at.write(old_file, "old content");
at.write(new_file, "new content");
ucmd.args(&["-i", "--update=none", new_file, old_file])
.succeeds()
.no_output();
assert_eq!(at.read(old_file), "old content");
assert_eq!(at.read(new_file), "new content");
}