mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cp: print verbose msg after prompt (#7287)
* cp: fix verbose output order after prompt Fixes: #7285 * cp: add test for verbose message order * cp: fix test for interactive prompt ordering * cp: update test for verbose output order * cp: fix test cases to use update option
This commit is contained in:
parent
64156516f8
commit
dd7b45465c
2 changed files with 43 additions and 4 deletions
|
@ -2271,10 +2271,6 @@ fn copy_file(
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.verbose {
|
|
||||||
print_verbose_output(options.parents, progress_bar, source, dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
if options.preserve_hard_links() {
|
if options.preserve_hard_links() {
|
||||||
// if we encounter a matching device/inode pair in the source tree
|
// if we encounter a matching device/inode pair in the source tree
|
||||||
// we can arrange to create a hard link between the corresponding names
|
// we can arrange to create a hard link between the corresponding names
|
||||||
|
@ -2284,6 +2280,11 @@ fn copy_file(
|
||||||
.context(format!("cannot stat {}", source.quote()))?,
|
.context(format!("cannot stat {}", source.quote()))?,
|
||||||
) {
|
) {
|
||||||
std::fs::hard_link(new_source, dest)?;
|
std::fs::hard_link(new_source, dest)?;
|
||||||
|
|
||||||
|
if options.verbose {
|
||||||
|
print_verbose_output(options.parents, progress_bar, source, dest);
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2334,6 +2335,10 @@ fn copy_file(
|
||||||
source_is_stream,
|
source_is_stream,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
if options.verbose {
|
||||||
|
print_verbose_output(options.parents, progress_bar, source, dest);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: implement something similar to gnu's lchown
|
// TODO: implement something similar to gnu's lchown
|
||||||
if !dest_is_symlink {
|
if !dest_is_symlink {
|
||||||
// Here, to match GNU semantics, we quietly ignore an error
|
// Here, to match GNU semantics, we quietly ignore an error
|
||||||
|
|
|
@ -6041,3 +6041,37 @@ fn test_cp_from_stdin() {
|
||||||
assert!(at.file_exists(target));
|
assert!(at.file_exists(target));
|
||||||
assert_eq!(at.read(target), test_string);
|
assert_eq!(at.read(target), test_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cp_update_older_interactive_prompt_yes() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let old_file = "old";
|
||||||
|
let new_file = "new";
|
||||||
|
|
||||||
|
let f = at.make_file(old_file);
|
||||||
|
f.set_modified(std::time::UNIX_EPOCH).unwrap();
|
||||||
|
at.touch(new_file);
|
||||||
|
|
||||||
|
ucmd.args(&["-i", "-v", "--update=older", new_file, old_file])
|
||||||
|
.pipe_in("Y\n")
|
||||||
|
.stderr_to_stdout()
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is("cp: overwrite 'old'? 'new' -> 'old'\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cp_update_older_interactive_prompt_no() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
let old_file = "old";
|
||||||
|
let new_file = "new";
|
||||||
|
|
||||||
|
let f = at.make_file(old_file);
|
||||||
|
f.set_modified(std::time::UNIX_EPOCH).unwrap();
|
||||||
|
at.touch(new_file);
|
||||||
|
|
||||||
|
ucmd.args(&["-i", "-v", "--update=older", new_file, old_file])
|
||||||
|
.pipe_in("N\n")
|
||||||
|
.stderr_to_stdout()
|
||||||
|
.fails()
|
||||||
|
.stdout_is("cp: overwrite 'old'? ");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue