mirror of
https://github.com/uutils/coreutils
synced 2024-12-12 14:22:41 +00:00
Merge pull request #5788 from cakebaker/mv_same_file
mv: show "same file" error for `mv d/f d`
This commit is contained in:
commit
527bb6fad8
2 changed files with 25 additions and 1 deletions
|
@ -314,6 +314,7 @@ fn handle_two_paths(source: &Path, target: &Path, opts: &Options) -> UResult<()>
|
|||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
if source.symlink_metadata().is_err() {
|
||||
return Err(if path_ends_with_terminator(source) {
|
||||
MvError::CannotStatNotADirectory(source.quote().to_string()).into()
|
||||
|
@ -336,6 +337,13 @@ fn handle_two_paths(source: &Path, target: &Path, opts: &Options) -> UResult<()>
|
|||
}
|
||||
}
|
||||
|
||||
if source.parent() == Some(target) {
|
||||
return Err(
|
||||
// use source twice to match GNU's error message
|
||||
MvError::SameFile(source.quote().to_string(), source.quote().to_string()).into(),
|
||||
);
|
||||
}
|
||||
|
||||
let target_is_dir = target.is_dir();
|
||||
let source_is_dir = source.is_dir();
|
||||
|
||||
|
|
|
@ -402,7 +402,23 @@ fn test_mv_same_file() {
|
|||
ucmd.arg(file_a)
|
||||
.arg(file_a)
|
||||
.fails()
|
||||
.stderr_is(format!("mv: '{file_a}' and '{file_a}' are the same file\n",));
|
||||
.stderr_is(format!("mv: '{file_a}' and '{file_a}' are the same file\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_file_to_same_dir() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file = "a";
|
||||
let dir = "dir";
|
||||
let path = &format!("{dir}/{file}");
|
||||
|
||||
at.mkdir(dir);
|
||||
at.touch(path);
|
||||
|
||||
ucmd.arg(path)
|
||||
.arg(dir)
|
||||
.fails()
|
||||
.stderr_is(format!("mv: '{path}' and '{path}' are the same file\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue