Skip to content

Commit

Permalink
Merge pull request #6861 from sylvestre/dup-source
Browse files Browse the repository at this point in the history
mv: fix the output of an error message
  • Loading branch information
cakebaker authored Nov 21, 2024
2 parents e37d2f2 + 7ffe3d4 commit 881044a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/uu/mv/src/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options)
format!(
"cannot move '{}' to a subdirectory of itself, '{}/{}'",
sourcepath.display(),
target_dir.display(),
uucore::fs::normalize_path(target_dir).display(),
canonicalized_target_dir.components().last().map_or_else(
|| target_dir.display().to_string(),
|dir| { PathBuf::from(dir.as_os_str()).display().to_string() }
Expand Down
20 changes: 20 additions & 0 deletions tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,3 +1732,23 @@ fn test_mv_error_msg_with_multiple_sources_that_does_not_exist() {
.stderr_contains("mv: cannot stat 'a': No such file or directory")
.stderr_contains("mv: cannot stat 'b/': No such file or directory");
}

#[test]
fn test_mv_error_cant_move_itself() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.mkdir("b");
scene
.ucmd()
.arg("b")
.arg("b/")
.fails()
.stderr_contains("mv: cannot move 'b' to a subdirectory of itself, 'b/b'");
scene
.ucmd()
.arg("./b")
.arg("b")
.arg("b/")
.fails()
.stderr_contains("mv: cannot move 'b' to a subdirectory of itself, 'b/b'");
}
13 changes: 13 additions & 0 deletions util/gnu-patches/tests_dup_source.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/tests/mv/dup-source.sh b/tests/mv/dup-source.sh
index 7bcd82fc3..0f9005296 100755
--- a/tests/mv/dup-source.sh
+++ b/tests/mv/dup-source.sh
@@ -83,7 +83,7 @@ $i: cannot stat 'a': No such file or directory
$i: cannot stat 'a': No such file or directory
$i: cannot stat 'b': No such file or directory
$i: cannot move './b' to a subdirectory of itself, 'b/b'
-$i: warning: source directory 'b' specified more than once
+$i: cannot move 'b' to a subdirectory of itself, 'b/b'
EOF
compare exp out || fail=1
done

0 comments on commit 881044a

Please sign in to comment.