Skip to content

Commit 191f238

Browse files
authored
Merge pull request uutils#4905 from sylvestre/mv-n
mv: Show 'skipped' when a file isn't overwriten
2 parents d1349b3 + d38797b commit 191f238

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/uu/mv/src/mv.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,19 @@ fn rename(
440440

441441
match b.overwrite {
442442
OverwriteMode::NoClobber => {
443-
return Err(io::Error::new(
444-
io::ErrorKind::Other,
445-
format!("not replacing {}", to.quote()),
446-
));
443+
let err_msg = if b.verbose {
444+
println!("skipped {}", to.quote());
445+
String::new()
446+
} else {
447+
format!("not replacing {}", to.quote())
448+
};
449+
return Err(io::Error::new(io::ErrorKind::Other, err_msg));
447450
}
448451
OverwriteMode::Interactive => {
449452
if !prompt_yes!("overwrite {}?", to.quote()) {
453+
if b.verbose {
454+
println!("skipped {}", to.quote());
455+
}
450456
return Err(io::Error::new(io::ErrorKind::Other, ""));
451457
}
452458
}

tests/by-util/test_mv.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,29 @@ fn test_mv_info_self() {
12431243
.stderr_contains("mv: cannot move 'dir2' to a subdirectory of itself, 'dir2/dir2'");
12441244
}
12451245

1246+
#[test]
1247+
fn test_mv_arg_interactive_skipped() {
1248+
let (at, mut ucmd) = at_and_ucmd!();
1249+
at.touch("a");
1250+
at.touch("b");
1251+
ucmd.args(&["-vi", "a", "b"])
1252+
.pipe_in("N\n")
1253+
.ignore_stdin_write_error()
1254+
.fails()
1255+
.stderr_is("mv: overwrite 'b'? ")
1256+
.stdout_is("skipped 'b'\n");
1257+
}
1258+
1259+
#[test]
1260+
fn test_mv_arg_interactive_skipped_vin() {
1261+
let (at, mut ucmd) = at_and_ucmd!();
1262+
at.touch("a");
1263+
at.touch("b");
1264+
ucmd.args(&["-vin", "a", "b"])
1265+
.fails()
1266+
.stdout_is("skipped 'b'\n");
1267+
}
1268+
12461269
#[test]
12471270
fn test_mv_into_self_data() {
12481271
let scene = TestScenario::new(util_name!());

0 commit comments

Comments
 (0)