Skip to content

Commit

Permalink
Merge pull request #5348 from cakebaker/cp_show_no_skipped_message
Browse files Browse the repository at this point in the history
cp: show no "skipped" msg with -vi/-vin
  • Loading branch information
tertsdiepraam committed Oct 3, 2023
2 parents 0f248d7 + 8ee69d2 commit 689b21d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
19 changes: 6 additions & 13 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,23 +1276,16 @@ fn copy_source(
}

impl OverwriteMode {
fn verify(&self, path: &Path, verbose: bool) -> CopyResult<()> {
fn verify(&self, path: &Path) -> CopyResult<()> {
match *self {
Self::NoClobber => {
if verbose {
println!("skipped {}", path.quote());
} else {
eprintln!("{}: not replacing {}", util_name(), path.quote());
}
eprintln!("{}: not replacing {}", util_name(), path.quote());
Err(Error::NotAllFilesCopied)
}
Self::Interactive(_) => {
if prompt_yes!("overwrite {}?", path.quote()) {
Ok(())
} else {
if verbose {
println!("skipped {}", path.quote());
}
Err(Error::Skipped)
}
}
Expand Down Expand Up @@ -1500,7 +1493,7 @@ fn handle_existing_dest(
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);
if let Some(backup_path) = backup_path {
Expand Down Expand Up @@ -1895,7 +1888,7 @@ fn copy_helper(
File::create(dest).context(dest.display().to_string())?;
} else if source_is_fifo && options.recursive && !options.copy_contents {
#[cfg(unix)]
copy_fifo(dest, options.overwrite, options.verbose)?;
copy_fifo(dest, options.overwrite)?;
} else if source_is_symlink {
copy_link(source, dest, symlinked_files)?;
} else {
Expand All @@ -1920,9 +1913,9 @@ fn copy_helper(
// "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).
#[cfg(unix)]
fn copy_fifo(dest: &Path, overwrite: OverwriteMode, verbose: bool) -> CopyResult<()> {
fn copy_fifo(dest: &Path, overwrite: OverwriteMode) -> CopyResult<()> {
if dest.exists() {
overwrite.verify(dest, verbose)?;
overwrite.verify(dest)?;
fs::remove_file(dest)?;
}

Expand Down
6 changes: 4 additions & 2 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ fn test_cp_arg_interactive_verbose() {
ucmd.args(&["-vi", "a", "b"])
.pipe_in("N\n")
.fails()
.stdout_is("skipped 'b'\n");
.stderr_is("cp: overwrite 'b'? ")
.no_stdout();
}

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

#[test]
Expand Down

0 comments on commit 689b21d

Please sign in to comment.