Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ quick_error! {
StripPrefixError(err: StripPrefixError) { from() }

/// Result of a skipped file
/// Currently happens when "no" is selected in interactive mode
Skipped { }

/// Result of a skipped file
Expand Down Expand Up @@ -1018,7 +1019,11 @@ fn show_error_if_needed(error: &Error) -> bool {
// When using --no-clobber, we don't want to show
// an error message
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);
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/uu/ln/src/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> UResult<()> {
match settings.overwrite {
OverwriteMode::NoClobber => {}
OverwriteMode::Interactive => {
if !prompt_yes!("overwrite {}?", dst.quote()) {
return Ok(());
if !prompt_yes!("replace {}?", dst.quote()) {
return Err(LnError::SomeLinksFailed.into());
}

if fs::remove_file(dst).is_ok() {};
Expand Down
2 changes: 1 addition & 1 deletion src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ fn rename(
OverwriteMode::NoClobber => return Ok(()),
OverwriteMode::Interactive => {
if !prompt_yes!("overwrite {}?", to.quote()) {
return Ok(());
return Err(io::Error::new(io::ErrorKind::Other, ""));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do something else than constructing an io::Error? This is going to give a weird error message isn't it? For a PR like this, I guess it's OK, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, there isn't any error message :)

$ touch a b && echo "n"|./target/debug/coreutils mv -i a b; echo $?
mv: overwrite 'b'? 
1

}
}
OverwriteMode::Force => {}
Expand Down
25 changes: 24 additions & 1 deletion tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,41 @@ fn test_cp_arg_update_interactive() {
.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]
fn test_cp_arg_interactive() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("a");
at.touch("b");
ucmd.args(&["-i", "a", "b"])
.pipe_in("N\n")
.succeeds()
.fails()
.no_stdout()
.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]
#[cfg(target_os = "linux")]
fn test_cp_arg_link() {
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn test_symlink_interactive() {
.ucmd()
.args(&["-i", "-s", file, link])
.pipe_in("n")
.succeeds()
.fails()
.no_stdout();

assert!(at.file_exists(file));
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn test_mv_interactive() {
.arg(file_a)
.arg(file_b)
.pipe_in("n")
.succeeds()
.fails()
.no_stdout();

assert!(at.file_exists(file_a));
Expand Down