Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mv: fix the output of an error message #6861

Merged
merged 1 commit into from
Nov 21, 2024
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
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
Loading