mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
bug(cp): like gnu/cp, don't show any message when --no-clobber is used
Simple example: touch bar rm -rf /tmp/foo mkdir -p /tmp/foo cp -pnL -v bar /tmp/foo echo $? cp -pnL -v bar /tmp/foo echo $? rm -rf /tmp/foo mkdir -p /tmp/foo ./target/debug/coreutils cp -pnL -v bar /tmp/foo echo $? ./target/debug/coreutils cp -pnL bar /tmp/foo echo $?
This commit is contained in:
parent
1e9820a7c4
commit
5a62dcafaa
2 changed files with 45 additions and 9 deletions
|
@ -814,10 +814,17 @@ fn copy(sources: &[Source], target: &Target, options: &Options) -> CopyResult<()
|
||||||
}
|
}
|
||||||
if !found_hard_link {
|
if !found_hard_link {
|
||||||
if let Err(error) = copy_source(source, target, &target_type, options) {
|
if let Err(error) = copy_source(source, target, &target_type, options) {
|
||||||
show_error!("{}", error);
|
|
||||||
match error {
|
match error {
|
||||||
Error::Skipped(_) => (),
|
// When using --no-clobber, we don't want to show
|
||||||
_ => non_fatal_errors = true,
|
// an error message
|
||||||
|
Error::NotAllFilesCopied => (),
|
||||||
|
Error::Skipped(_) => {
|
||||||
|
show_error!("{}", error);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
show_error!("{}", error);
|
||||||
|
non_fatal_errors = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -993,11 +1000,7 @@ fn copy_directory(root: &Path, target: &Target, options: &Options) -> CopyResult
|
||||||
impl OverwriteMode {
|
impl OverwriteMode {
|
||||||
fn verify(&self, path: &Path) -> CopyResult<()> {
|
fn verify(&self, path: &Path) -> CopyResult<()> {
|
||||||
match *self {
|
match *self {
|
||||||
OverwriteMode::NoClobber => Err(Error::Skipped(format!(
|
OverwriteMode::NoClobber => Err(Error::NotAllFilesCopied),
|
||||||
"Not overwriting {} because of option '{}'",
|
|
||||||
path.display(),
|
|
||||||
OPT_NO_CLOBBER
|
|
||||||
))),
|
|
||||||
OverwriteMode::Interactive(_) => {
|
OverwriteMode::Interactive(_) => {
|
||||||
if prompt_yes!("{}: overwrite {}? ", executable!(), path.display()) {
|
if prompt_yes!("{}: overwrite {}? ", executable!(), path.display()) {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -255,7 +255,40 @@ fn test_cp_arg_no_clobber() {
|
||||||
|
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "How are you?\n");
|
||||||
assert!(result.stderr.contains("Not overwriting"));
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cp_arg_no_clobber_twice() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
at.touch("source.txt");
|
||||||
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--no-clobber")
|
||||||
|
.arg("source.txt")
|
||||||
|
.arg("dest.txt")
|
||||||
|
.run();
|
||||||
|
|
||||||
|
println!("stderr = {:?}", result.stderr);
|
||||||
|
println!("stdout = {:?}", result.stdout);
|
||||||
|
assert!(result.success);
|
||||||
|
assert!(result.stderr.is_empty());
|
||||||
|
assert_eq!(at.read("source.txt"), "");
|
||||||
|
|
||||||
|
at.append("source.txt", "some-content");
|
||||||
|
let result = scene
|
||||||
|
.ucmd()
|
||||||
|
.arg("--no-clobber")
|
||||||
|
.arg("source.txt")
|
||||||
|
.arg("dest.txt")
|
||||||
|
.run();
|
||||||
|
|
||||||
|
assert!(result.success);
|
||||||
|
assert_eq!(at.read("source.txt"), "some-content");
|
||||||
|
// Should be empty as the "no-clobber" should keep
|
||||||
|
// the previous version
|
||||||
|
assert_eq!(at.read("dest.txt"), "");
|
||||||
|
assert!(!result.stderr.contains("Not overwriting"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue