mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
fix: simplify logic
This commit is contained in:
parent
991fcc548c
commit
e5e7ca8dc5
1 changed files with 14 additions and 24 deletions
|
@ -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();
|
|
||||||
let is_perm_denied = error_as_str.contains("Permission denied");
|
|
||||||
match e.kind() {
|
|
||||||
_ => {
|
|
||||||
show_error!(
|
show_error!(
|
||||||
"cannot move ‘{}’ to ‘{}’: {}",
|
"cannot move ‘{}’ to ‘{}’: {}",
|
||||||
source.display(),
|
source.display(),
|
||||||
target.display(),
|
target.display(),
|
||||||
if is_perm_denied {
|
|
||||||
"Permission denied".to_string()
|
|
||||||
} else {
|
|
||||||
e.to_string()
|
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 {
|
|
||||||
"Permission denied".to_string()
|
|
||||||
} else {
|
|
||||||
e.to_string()
|
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))?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue