mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
Merge pull request #4630 from sylvestre/inter-error
Adjust -i behavior for ln, cp & mv
This commit is contained in:
commit
ef601fac98
6 changed files with 35 additions and 7 deletions
|
@ -78,6 +78,7 @@ quick_error! {
|
||||||
StripPrefixError(err: StripPrefixError) { from() }
|
StripPrefixError(err: StripPrefixError) { from() }
|
||||||
|
|
||||||
/// Result of a skipped file
|
/// Result of a skipped file
|
||||||
|
/// Currently happens when "no" is selected in interactive mode
|
||||||
Skipped { }
|
Skipped { }
|
||||||
|
|
||||||
/// Result of a skipped file
|
/// Result of a skipped file
|
||||||
|
@ -1018,7 +1019,11 @@ fn show_error_if_needed(error: &Error) -> bool {
|
||||||
// When using --no-clobber, we don't want to show
|
// When using --no-clobber, we don't want to show
|
||||||
// an error message
|
// an error message
|
||||||
Error::NotAllFilesCopied => (),
|
Error::NotAllFilesCopied => (),
|
||||||
Error::Skipped => (),
|
Error::Skipped => {
|
||||||
|
// touch a b && echo "n"|cp -i a b && echo $?
|
||||||
|
// should return an error from GNU 9.2
|
||||||
|
return true;
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
show_error!("{}", error);
|
show_error!("{}", error);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -391,8 +391,8 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> {
|
||||||
match settings.overwrite {
|
match settings.overwrite {
|
||||||
OverwriteMode::NoClobber => {}
|
OverwriteMode::NoClobber => {}
|
||||||
OverwriteMode::Interactive => {
|
OverwriteMode::Interactive => {
|
||||||
if !prompt_yes!("overwrite {}?", dst.quote()) {
|
if !prompt_yes!("replace {}?", dst.quote()) {
|
||||||
return Ok(());
|
return Err(LnError::SomeLinksFailed.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if fs::remove_file(dst).is_ok() {};
|
if fs::remove_file(dst).is_ok() {};
|
||||||
|
|
|
@ -420,7 +420,7 @@ fn rename(
|
||||||
OverwriteMode::NoClobber => return Ok(()),
|
OverwriteMode::NoClobber => return Ok(()),
|
||||||
OverwriteMode::Interactive => {
|
OverwriteMode::Interactive => {
|
||||||
if !prompt_yes!("overwrite {}?", to.quote()) {
|
if !prompt_yes!("overwrite {}?", to.quote()) {
|
||||||
return Ok(());
|
return Err(io::Error::new(io::ErrorKind::Other, ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OverwriteMode::Force => {}
|
OverwriteMode::Force => {}
|
||||||
|
|
|
@ -234,6 +234,16 @@ fn test_cp_arg_update_interactive() {
|
||||||
.no_stderr();
|
.no_stderr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cp_arg_update_interactive_error() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg(TEST_HELLO_WORLD_SOURCE)
|
||||||
|
.arg(TEST_HOW_ARE_YOU_SOURCE)
|
||||||
|
.arg("-i")
|
||||||
|
.fails()
|
||||||
|
.no_stdout();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_arg_interactive() {
|
fn test_cp_arg_interactive() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
@ -241,11 +251,24 @@ fn test_cp_arg_interactive() {
|
||||||
at.touch("b");
|
at.touch("b");
|
||||||
ucmd.args(&["-i", "a", "b"])
|
ucmd.args(&["-i", "a", "b"])
|
||||||
.pipe_in("N\n")
|
.pipe_in("N\n")
|
||||||
.succeeds()
|
.fails()
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("cp: overwrite 'b'? ");
|
.stderr_is("cp: overwrite 'b'? ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cp_arg_interactive_update() {
|
||||||
|
// -u -i won't show the prompt to validate the override or not
|
||||||
|
// Therefore, the error code will be 0
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.touch("a");
|
||||||
|
at.touch("b");
|
||||||
|
ucmd.args(&["-i", "-u", "a", "b"])
|
||||||
|
.pipe_in("N\n")
|
||||||
|
.succeeds()
|
||||||
|
.no_stdout();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn test_cp_arg_link() {
|
fn test_cp_arg_link() {
|
||||||
|
|
|
@ -116,7 +116,7 @@ fn test_symlink_interactive() {
|
||||||
.ucmd()
|
.ucmd()
|
||||||
.args(&["-i", "-s", file, link])
|
.args(&["-i", "-s", file, link])
|
||||||
.pipe_in("n")
|
.pipe_in("n")
|
||||||
.succeeds()
|
.fails()
|
||||||
.no_stdout();
|
.no_stdout();
|
||||||
|
|
||||||
assert!(at.file_exists(file));
|
assert!(at.file_exists(file));
|
||||||
|
|
|
@ -165,7 +165,7 @@ fn test_mv_interactive() {
|
||||||
.arg(file_a)
|
.arg(file_a)
|
||||||
.arg(file_b)
|
.arg(file_b)
|
||||||
.pipe_in("n")
|
.pipe_in("n")
|
||||||
.succeeds()
|
.fails()
|
||||||
.no_stdout();
|
.no_stdout();
|
||||||
|
|
||||||
assert!(at.file_exists(file_a));
|
assert!(at.file_exists(file_a));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue