mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 01:38:04 +00:00
Merge pull request #3392 from sylvestre/mv-itself
mv: trigger an error when doing mv dir1 dir2 dir2
This commit is contained in:
commit
8cd359c556
2 changed files with 35 additions and 1 deletions
|
@ -285,7 +285,23 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> {
|
|||
));
|
||||
}
|
||||
let target_dir = paths.last().unwrap();
|
||||
move_files_into_dir(&paths[..paths.len() - 1], target_dir, b)
|
||||
let sources = &paths[..paths.len() - 1];
|
||||
|
||||
// Check if we have mv dir1 dir2 dir2
|
||||
// And generate an error if this is the case
|
||||
if sources.contains(target_dir) {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format!(
|
||||
"cannot move {} to a subdirectory of itself, '{}/{}'",
|
||||
target_dir.quote(),
|
||||
target_dir.display(),
|
||||
target_dir.display()
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
move_files_into_dir(sources, target_dir, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -823,6 +823,24 @@ fn test_mv_interactive_error() {
|
|||
.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_info_self() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let dir1 = "dir1";
|
||||
let dir2 = "dir2";
|
||||
at.mkdir(dir1);
|
||||
at.mkdir(dir2);
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(dir1)
|
||||
.arg(dir2)
|
||||
.arg(dir2)
|
||||
.fails()
|
||||
.stderr_contains("mv: cannot move 'dir2' to a subdirectory of itself, 'dir2/dir2'");
|
||||
}
|
||||
|
||||
// Todo:
|
||||
|
||||
// $ at.touch a b
|
||||
|
|
Loading…
Reference in a new issue