mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 07:12:44 +00:00
Merge pull request #4802 from cakebaker/mv_validate_target_arg
mv: validate --target arg
This commit is contained in:
commit
400cf11620
1 changed files with 12 additions and 9 deletions
|
@ -106,14 +106,22 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
let backup_suffix = backup_control::determine_backup_suffix(&matches);
|
let backup_suffix = backup_control::determine_backup_suffix(&matches);
|
||||||
|
|
||||||
|
let target_dir = matches
|
||||||
|
.get_one::<OsString>(OPT_TARGET_DIRECTORY)
|
||||||
|
.map(OsString::from);
|
||||||
|
|
||||||
|
if let Some(ref maybe_dir) = target_dir {
|
||||||
|
if !Path::new(&maybe_dir).is_dir() {
|
||||||
|
return Err(MvError::TargetNotADirectory(maybe_dir.quote().to_string()).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let behavior = Behavior {
|
let behavior = Behavior {
|
||||||
overwrite: overwrite_mode,
|
overwrite: overwrite_mode,
|
||||||
backup: backup_mode,
|
backup: backup_mode,
|
||||||
suffix: backup_suffix,
|
suffix: backup_suffix,
|
||||||
update: matches.get_flag(OPT_UPDATE),
|
update: matches.get_flag(OPT_UPDATE),
|
||||||
target_dir: matches
|
target_dir,
|
||||||
.get_one::<OsString>(OPT_TARGET_DIRECTORY)
|
|
||||||
.map(OsString::from),
|
|
||||||
no_target_dir: matches.get_flag(OPT_NO_TARGET_DIRECTORY),
|
no_target_dir: matches.get_flag(OPT_NO_TARGET_DIRECTORY),
|
||||||
verbose: matches.get_flag(OPT_VERBOSE),
|
verbose: matches.get_flag(OPT_VERBOSE),
|
||||||
strip_slashes: matches.get_flag(OPT_STRIP_TRAILING_SLASHES),
|
strip_slashes: matches.get_flag(OPT_STRIP_TRAILING_SLASHES),
|
||||||
|
@ -320,12 +328,7 @@ fn exec(files: &[OsString], b: &Behavior) -> UResult<()> {
|
||||||
|
|
||||||
fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UResult<()> {
|
fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UResult<()> {
|
||||||
if !target_dir.is_dir() {
|
if !target_dir.is_dir() {
|
||||||
match b.target_dir {
|
return Err(MvError::NotADirectory(target_dir.quote().to_string()).into());
|
||||||
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
|
let canonized_target_dir = target_dir
|
||||||
|
|
Loading…
Reference in a new issue