Skip to content

Commit 7ea11c2

Browse files
hz2cakebaker
authored andcommitted
cp: fix update prompting (uutils#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 uutils#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>
1 parent bb280de commit 7ea11c2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/uu/cp/src/cp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,13 @@ fn handle_existing_dest(
18281828
return Err(format!("{} and {} are the same file", source.quote(), dest.quote()).into());
18291829
}
18301830

1831+
if options.update == UpdateMode::ReplaceNone {
1832+
if options.debug {
1833+
println!("skipped {}", dest.quote());
1834+
}
1835+
return Err(Error::Skipped(false));
1836+
}
1837+
18311838
if options.update != UpdateMode::ReplaceIfOlder {
18321839
options.overwrite.verify(dest, options.debug)?;
18331840
}

tests/by-util/test_cp.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6167,3 +6167,20 @@ fn test_cp_update_older_interactive_prompt_no() {
61676167
.fails()
61686168
.stdout_is("cp: overwrite 'old'? ");
61696169
}
6170+
6171+
#[test]
6172+
fn test_cp_update_none_interactive_prompt_no() {
6173+
let (at, mut ucmd) = at_and_ucmd!();
6174+
let old_file = "old";
6175+
let new_file = "new";
6176+
6177+
at.write(old_file, "old content");
6178+
at.write(new_file, "new content");
6179+
6180+
ucmd.args(&["-i", "--update=none", new_file, old_file])
6181+
.succeeds()
6182+
.no_output();
6183+
6184+
assert_eq!(at.read(old_file), "old content");
6185+
assert_eq!(at.read(new_file), "new content");
6186+
}

0 commit comments

Comments
 (0)