1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

fix: simplify logic

This commit is contained in:
Yağız can Değirmenci 2021-05-24 21:20:59 +03:00
parent 991fcc548c
commit e5e7ca8dc5

View file

@ -291,22 +291,12 @@ fn exec(files: &[PathBuf], b: Behavior) -> i32 {
return match rename(source, target, &b) { return match rename(source, target, &b) {
Err(e) => { Err(e) => {
let error_as_str = e.to_string(); show_error!(
let is_perm_denied = error_as_str.contains("Permission denied"); "cannot move {} to {}: {}",
match e.kind() { source.display(),
_ => { target.display(),
show_error!( e.to_string()
"cannot move {} to {}: {}", );
source.display(),
target.display(),
if is_perm_denied {
"Permission denied".to_string()
} else {
e.to_string()
}
);
}
}
1 1
} }
_ => 0, _ => 0,
@ -367,17 +357,11 @@ fn move_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> i3
}; };
if let Err(e) = rename(sourcepath, &targetpath, b) { if let Err(e) = rename(sourcepath, &targetpath, b) {
let error_as_str = e.to_string();
let is_perm_denied = error_as_str.contains("Permission denied");
show_error!( show_error!(
"cannot move {} to {}: {}", "cannot move {} to {}: {}",
sourcepath.display(), sourcepath.display(),
targetpath.display(), targetpath.display(),
if is_perm_denied { e.to_string()
"Permission denied".to_string()
} else {
e.to_string()
}
); );
all_successful = false; all_successful = false;
} }
@ -469,7 +453,13 @@ fn rename_with_fallback(from: &Path, to: &Path) -> io::Result<()> {
..DirCopyOptions::new() ..DirCopyOptions::new()
}; };
if let Err(err) = move_dir(from, to, &options) { if let Err(err) = move_dir(from, to, &options) {
return Err(io::Error::new(io::ErrorKind::Other, format!("{:?}", err))); return match err.kind {
fs_extra::error::ErrorKind::PermissionDenied => Err(io::Error::new(
io::ErrorKind::PermissionDenied,
"Permission denied",
)),
_ => Err(io::Error::new(io::ErrorKind::Other, format!("{:?}", err))),
};
} }
} else { } else {
fs::copy(from, to).and_then(|_| fs::remove_file(from))?; fs::copy(from, to).and_then(|_| fs::remove_file(from))?;