Skip to content

Commit 881044a

Browse files
authored
Merge pull request #6861 from sylvestre/dup-source
mv: fix the output of an error message
2 parents e37d2f2 + 7ffe3d4 commit 881044a

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/uu/mv/src/mv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, options: &Options)
488488
format!(
489489
"cannot move '{}' to a subdirectory of itself, '{}/{}'",
490490
sourcepath.display(),
491-
target_dir.display(),
491+
uucore::fs::normalize_path(target_dir).display(),
492492
canonicalized_target_dir.components().last().map_or_else(
493493
|| target_dir.display().to_string(),
494494
|dir| { PathBuf::from(dir.as_os_str()).display().to_string() }

tests/by-util/test_mv.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,3 +1732,23 @@ fn test_mv_error_msg_with_multiple_sources_that_does_not_exist() {
17321732
.stderr_contains("mv: cannot stat 'a': No such file or directory")
17331733
.stderr_contains("mv: cannot stat 'b/': No such file or directory");
17341734
}
1735+
1736+
#[test]
1737+
fn test_mv_error_cant_move_itself() {
1738+
let scene = TestScenario::new(util_name!());
1739+
let at = &scene.fixtures;
1740+
at.mkdir("b");
1741+
scene
1742+
.ucmd()
1743+
.arg("b")
1744+
.arg("b/")
1745+
.fails()
1746+
.stderr_contains("mv: cannot move 'b' to a subdirectory of itself, 'b/b'");
1747+
scene
1748+
.ucmd()
1749+
.arg("./b")
1750+
.arg("b")
1751+
.arg("b/")
1752+
.fails()
1753+
.stderr_contains("mv: cannot move 'b' to a subdirectory of itself, 'b/b'");
1754+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/tests/mv/dup-source.sh b/tests/mv/dup-source.sh
2+
index 7bcd82fc3..0f9005296 100755
3+
--- a/tests/mv/dup-source.sh
4+
+++ b/tests/mv/dup-source.sh
5+
@@ -83,7 +83,7 @@ $i: cannot stat 'a': No such file or directory
6+
$i: cannot stat 'a': No such file or directory
7+
$i: cannot stat 'b': No such file or directory
8+
$i: cannot move './b' to a subdirectory of itself, 'b/b'
9+
-$i: warning: source directory 'b' specified more than once
10+
+$i: cannot move 'b' to a subdirectory of itself, 'b/b'
11+
EOF
12+
compare exp out || fail=1
13+
done

0 commit comments

Comments
 (0)