1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

mv: check if --target is a directory

This commit is contained in:
John Shin 2023-04-26 09:47:03 -07:00
parent 6f0e4ece9d
commit aeeb3c90cf
2 changed files with 9 additions and 2 deletions

View file

@ -15,6 +15,7 @@ pub enum MvError {
DirectoryToNonDirectory(String),
NonDirectoryToDirectory(String, String),
NotADirectory(String),
TargetNotADirectory(String),
}
impl Error for MvError {}
@ -34,7 +35,8 @@ impl Display for MvError {
Self::NonDirectoryToDirectory(s, t) => {
write!(f, "cannot overwrite non-directory {t} with directory {s}")
}
Self::NotADirectory(t) => write!(f, "target {t} is not a directory"),
Self::NotADirectory(t) => write!(f, "target {t}: Not a directory"),
Self::TargetNotADirectory(t) => write!(f, "target directory {t}: Not a directory"),
}
}
}

View file

@ -320,7 +320,12 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> {
fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UResult<()> {
if !target_dir.is_dir() {
return Err(MvError::NotADirectory(target_dir.quote().to_string()).into());
match b.target_dir {
Some(_) => {
return Err(MvError::TargetNotADirectory(target_dir.quote().to_string()).into())
}
None => return Err(MvError::NotADirectory(target_dir.quote().to_string()).into()),
}
}
let canonized_target_dir = target_dir