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

Merge pull request #5348 from cakebaker/cp_show_no_skipped_message

cp: show no "skipped" msg with -vi/-vin
This commit is contained in:
Terts Diepraam 2023-10-03 11:58:47 +02:00 committed by GitHub
commit 689b21d0b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 15 deletions

View file

@ -1276,23 +1276,16 @@ fn copy_source(
} }
impl OverwriteMode { impl OverwriteMode {
fn verify(&self, path: &Path, verbose: bool) -> CopyResult<()> { fn verify(&self, path: &Path) -> CopyResult<()> {
match *self { match *self {
Self::NoClobber => { Self::NoClobber => {
if verbose { eprintln!("{}: not replacing {}", util_name(), path.quote());
println!("skipped {}", path.quote());
} else {
eprintln!("{}: not replacing {}", util_name(), path.quote());
}
Err(Error::NotAllFilesCopied) Err(Error::NotAllFilesCopied)
} }
Self::Interactive(_) => { Self::Interactive(_) => {
if prompt_yes!("overwrite {}?", path.quote()) { if prompt_yes!("overwrite {}?", path.quote()) {
Ok(()) Ok(())
} else { } else {
if verbose {
println!("skipped {}", path.quote());
}
Err(Error::Skipped) Err(Error::Skipped)
} }
} }
@ -1500,7 +1493,7 @@ fn handle_existing_dest(
return Err(format!("{} and {} are the same file", source.quote(), dest.quote()).into()); return Err(format!("{} and {} are the same file", source.quote(), dest.quote()).into());
} }
options.overwrite.verify(dest, options.verbose)?; options.overwrite.verify(dest)?;
let backup_path = backup_control::get_backup_path(options.backup, dest, &options.backup_suffix); let backup_path = backup_control::get_backup_path(options.backup, dest, &options.backup_suffix);
if let Some(backup_path) = backup_path { if let Some(backup_path) = backup_path {
@ -1895,7 +1888,7 @@ fn copy_helper(
File::create(dest).context(dest.display().to_string())?; File::create(dest).context(dest.display().to_string())?;
} else if source_is_fifo && options.recursive && !options.copy_contents { } else if source_is_fifo && options.recursive && !options.copy_contents {
#[cfg(unix)] #[cfg(unix)]
copy_fifo(dest, options.overwrite, options.verbose)?; copy_fifo(dest, options.overwrite)?;
} else if source_is_symlink { } else if source_is_symlink {
copy_link(source, dest, symlinked_files)?; copy_link(source, dest, symlinked_files)?;
} else { } else {
@ -1920,9 +1913,9 @@ fn copy_helper(
// "Copies" a FIFO by creating a new one. This workaround is because Rust's // "Copies" a FIFO by creating a new one. This workaround is because Rust's
// built-in fs::copy does not handle FIFOs (see rust-lang/rust/issues/79390). // built-in fs::copy does not handle FIFOs (see rust-lang/rust/issues/79390).
#[cfg(unix)] #[cfg(unix)]
fn copy_fifo(dest: &Path, overwrite: OverwriteMode, verbose: bool) -> CopyResult<()> { fn copy_fifo(dest: &Path, overwrite: OverwriteMode) -> CopyResult<()> {
if dest.exists() { if dest.exists() {
overwrite.verify(dest, verbose)?; overwrite.verify(dest)?;
fs::remove_file(dest)?; fs::remove_file(dest)?;
} }

View file

@ -483,7 +483,8 @@ fn test_cp_arg_interactive_verbose() {
ucmd.args(&["-vi", "a", "b"]) ucmd.args(&["-vi", "a", "b"])
.pipe_in("N\n") .pipe_in("N\n")
.fails() .fails()
.stdout_is("skipped 'b'\n"); .stderr_is("cp: overwrite 'b'? ")
.no_stdout();
} }
#[test] #[test]
@ -494,7 +495,8 @@ fn test_cp_arg_interactive_verbose_clobber() {
at.touch("b"); at.touch("b");
ucmd.args(&["-vin", "a", "b"]) ucmd.args(&["-vin", "a", "b"])
.fails() .fails()
.stdout_is("skipped 'b'\n"); .stderr_is("cp: not replacing 'b'\n")
.no_stdout();
} }
#[test] #[test]