mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
chore: clean up a few code paths
* `cp`: in `copy_dir.rs`, remove duplicate copy_file() calls and streamline error handling * `install`: simplify `preserve_timestamp` * `tee` - simplify error handling
This commit is contained in:
parent
5bfbc30fba
commit
b09cd32534
3 changed files with 37 additions and 57 deletions
|
@ -264,55 +264,40 @@ fn copy_direntry(
|
||||||
|
|
||||||
// If the source is not a directory, then we need to copy the file.
|
// If the source is not a directory, then we need to copy the file.
|
||||||
if !source_absolute.is_dir() {
|
if !source_absolute.is_dir() {
|
||||||
if preserve_hard_links {
|
if let Err(err) = copy_file(
|
||||||
match copy_file(
|
progress_bar,
|
||||||
progress_bar,
|
&source_absolute,
|
||||||
&source_absolute,
|
local_to_target.as_path(),
|
||||||
local_to_target.as_path(),
|
options,
|
||||||
options,
|
symlinked_files,
|
||||||
symlinked_files,
|
copied_destinations,
|
||||||
copied_destinations,
|
copied_files,
|
||||||
copied_files,
|
false,
|
||||||
false,
|
) {
|
||||||
) {
|
if preserve_hard_links {
|
||||||
Ok(_) => Ok(()),
|
if !source_absolute.is_symlink() {
|
||||||
Err(err) => {
|
return Err(err);
|
||||||
if source_absolute.is_symlink() {
|
}
|
||||||
// silent the error with a symlink
|
// silent the error with a symlink
|
||||||
// In case we do --archive, we might copy the symlink
|
// In case we do --archive, we might copy the symlink
|
||||||
// before the file itself
|
// before the file itself
|
||||||
Ok(())
|
} else {
|
||||||
} else {
|
// At this point, `path` is just a plain old file.
|
||||||
Err(err)
|
// Terminate this function immediately if there is any
|
||||||
|
// kind of error *except* a "permission denied" error.
|
||||||
|
//
|
||||||
|
// TODO What other kinds of errors, if any, should
|
||||||
|
// cause us to continue walking the directory?
|
||||||
|
match err {
|
||||||
|
Error::IoErrContext(e, _) if e.kind() == io::ErrorKind::PermissionDenied => {
|
||||||
|
show!(uio_error!(
|
||||||
|
e,
|
||||||
|
"cannot open {} for reading",
|
||||||
|
source_relative.quote(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
e => return Err(e),
|
||||||
}
|
}
|
||||||
}?;
|
|
||||||
} else {
|
|
||||||
// At this point, `path` is just a plain old file.
|
|
||||||
// Terminate this function immediately if there is any
|
|
||||||
// kind of error *except* a "permission denied" error.
|
|
||||||
//
|
|
||||||
// TODO What other kinds of errors, if any, should
|
|
||||||
// cause us to continue walking the directory?
|
|
||||||
match copy_file(
|
|
||||||
progress_bar,
|
|
||||||
&source_absolute,
|
|
||||||
local_to_target.as_path(),
|
|
||||||
options,
|
|
||||||
symlinked_files,
|
|
||||||
copied_destinations,
|
|
||||||
copied_files,
|
|
||||||
false,
|
|
||||||
) {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(Error::IoErrContext(e, _)) if e.kind() == io::ErrorKind::PermissionDenied => {
|
|
||||||
show!(uio_error!(
|
|
||||||
e,
|
|
||||||
"cannot open {} for reading",
|
|
||||||
source_relative.quote(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Err(e) => return Err(e),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -867,13 +867,11 @@ fn preserve_timestamps(from: &Path, to: &Path) -> UResult<()> {
|
||||||
let modified_time = FileTime::from_last_modification_time(&meta);
|
let modified_time = FileTime::from_last_modification_time(&meta);
|
||||||
let accessed_time = FileTime::from_last_access_time(&meta);
|
let accessed_time = FileTime::from_last_access_time(&meta);
|
||||||
|
|
||||||
match set_file_times(to, accessed_time, modified_time) {
|
if let Err(e) = set_file_times(to, accessed_time, modified_time) {
|
||||||
Ok(_) => Ok(()),
|
show_error!("{e}");
|
||||||
Err(e) => {
|
// ignore error
|
||||||
show_error!("{e}");
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copy one file to a new location, changing metadata.
|
/// Copy one file to a new location, changing metadata.
|
||||||
|
|
|
@ -91,10 +91,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
output_error,
|
output_error,
|
||||||
};
|
};
|
||||||
|
|
||||||
match tee(&options) {
|
tee(&options).map_err(|_| 1.into())
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(_) => Err(1.into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> Command {
|
pub fn uu_app() -> Command {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue