Skip to content

Commit 4bc5185

Browse files
authored
Merge pull request #7725 from nyurik/code-opt
chore: clean up a few code paths
2 parents 5bfbc30 + b09cd32 commit 4bc5185

File tree

3 files changed

+37
-57
lines changed

3 files changed

+37
-57
lines changed

src/uu/cp/src/copydir.rs

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -264,55 +264,40 @@ fn copy_direntry(
264264

265265
// If the source is not a directory, then we need to copy the file.
266266
if !source_absolute.is_dir() {
267-
if preserve_hard_links {
268-
match copy_file(
269-
progress_bar,
270-
&source_absolute,
271-
local_to_target.as_path(),
272-
options,
273-
symlinked_files,
274-
copied_destinations,
275-
copied_files,
276-
false,
277-
) {
278-
Ok(_) => Ok(()),
279-
Err(err) => {
280-
if source_absolute.is_symlink() {
281-
// silent the error with a symlink
282-
// In case we do --archive, we might copy the symlink
283-
// before the file itself
284-
Ok(())
285-
} else {
286-
Err(err)
287-
}
267+
if let Err(err) = copy_file(
268+
progress_bar,
269+
&source_absolute,
270+
local_to_target.as_path(),
271+
options,
272+
symlinked_files,
273+
copied_destinations,
274+
copied_files,
275+
false,
276+
) {
277+
if preserve_hard_links {
278+
if !source_absolute.is_symlink() {
279+
return Err(err);
288280
}
289-
}?;
290-
} else {
291-
// At this point, `path` is just a plain old file.
292-
// Terminate this function immediately if there is any
293-
// kind of error *except* a "permission denied" error.
294-
//
295-
// TODO What other kinds of errors, if any, should
296-
// cause us to continue walking the directory?
297-
match copy_file(
298-
progress_bar,
299-
&source_absolute,
300-
local_to_target.as_path(),
301-
options,
302-
symlinked_files,
303-
copied_destinations,
304-
copied_files,
305-
false,
306-
) {
307-
Ok(_) => {}
308-
Err(Error::IoErrContext(e, _)) if e.kind() == io::ErrorKind::PermissionDenied => {
309-
show!(uio_error!(
310-
e,
311-
"cannot open {} for reading",
312-
source_relative.quote(),
313-
));
281+
// silent the error with a symlink
282+
// In case we do --archive, we might copy the symlink
283+
// before the file itself
284+
} else {
285+
// At this point, `path` is just a plain old file.
286+
// Terminate this function immediately if there is any
287+
// kind of error *except* a "permission denied" error.
288+
//
289+
// TODO What other kinds of errors, if any, should
290+
// cause us to continue walking the directory?
291+
match err {
292+
Error::IoErrContext(e, _) if e.kind() == io::ErrorKind::PermissionDenied => {
293+
show!(uio_error!(
294+
e,
295+
"cannot open {} for reading",
296+
source_relative.quote(),
297+
));
298+
}
299+
e => return Err(e),
314300
}
315-
Err(e) => return Err(e),
316301
}
317302
}
318303
}

src/uu/install/src/install.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,11 @@ fn preserve_timestamps(from: &Path, to: &Path) -> UResult<()> {
867867
let modified_time = FileTime::from_last_modification_time(&meta);
868868
let accessed_time = FileTime::from_last_access_time(&meta);
869869

870-
match set_file_times(to, accessed_time, modified_time) {
871-
Ok(_) => Ok(()),
872-
Err(e) => {
873-
show_error!("{e}");
874-
Ok(())
875-
}
870+
if let Err(e) = set_file_times(to, accessed_time, modified_time) {
871+
show_error!("{e}");
872+
// ignore error
876873
}
874+
Ok(())
877875
}
878876

879877
/// Copy one file to a new location, changing metadata.

src/uu/tee/src/tee.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
9191
output_error,
9292
};
9393

94-
match tee(&options) {
95-
Ok(_) => Ok(()),
96-
Err(_) => Err(1.into()),
97-
}
94+
tee(&options).map_err(|_| 1.into())
9895
}
9996

10097
pub fn uu_app() -> Command {

0 commit comments

Comments
 (0)