mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #1660 from sylvestre/cp-2
bug(cp): like gnu/cp, don't show any message when --no-clobber is used
This commit is contained in:
commit
909acdfeb4
4 changed files with 53 additions and 12 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(())
|
||||||
|
|
|
@ -12,6 +12,8 @@ extern crate uucore;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::{copy, sink, stdin, stdout, Error, ErrorKind, Read, Result, Write};
|
use std::io::{copy, sink, stdin, stdout, Error, ErrorKind, Read, Result, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
use uucore::libc;
|
use uucore::libc;
|
||||||
|
|
||||||
static NAME: &str = "tee";
|
static NAME: &str = "tee";
|
||||||
|
|
|
@ -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]
|
||||||
|
|
|
@ -289,18 +289,21 @@ fn test_ls_ls_color() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ls_human() {
|
fn test_ls_human() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let at = &scene.fixtures;
|
|
||||||
let file = "test_human";
|
let file = "test_human";
|
||||||
let result = scene.cmd("truncate").arg("-s").arg("+1000").arg(file).run();
|
let result = scene.cmd("truncate").arg("-s").arg("+1000").arg(file).run();
|
||||||
println!("stderr = {:?}", result.stderr);
|
println!("stderr = {:?}", result.stderr);
|
||||||
println!("stdout = {:?}", result.stdout);
|
println!("stdout = {:?}", result.stdout);
|
||||||
assert!(result.success);
|
|
||||||
let result = scene.ucmd().arg("-hl").arg(file).run();
|
let result = scene.ucmd().arg("-hl").arg(file).run();
|
||||||
println!("stderr = {:?}", result.stderr);
|
println!("stderr = {:?}", result.stderr);
|
||||||
println!("stdout = {:?}", result.stdout);
|
println!("stdout = {:?}", result.stdout);
|
||||||
assert!(result.success);
|
assert!(result.success);
|
||||||
assert!(result.stdout.contains("1.00K"));
|
assert!(result.stdout.contains("1.00K"));
|
||||||
let result = scene.cmd("truncate").arg("-s").arg("+1000k").arg(file).run();
|
scene
|
||||||
|
.cmd("truncate")
|
||||||
|
.arg("-s")
|
||||||
|
.arg("+1000k")
|
||||||
|
.arg(file)
|
||||||
|
.run();
|
||||||
let result = scene.ucmd().arg("-hl").arg(file).run();
|
let result = scene.ucmd().arg("-hl").arg(file).run();
|
||||||
println!("stderr = {:?}", result.stderr);
|
println!("stderr = {:?}", result.stderr);
|
||||||
println!("stdout = {:?}", result.stdout);
|
println!("stdout = {:?}", result.stdout);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue