From 2a7831bd94a944a084ed0a6879a2dbe12c32c8c2 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Wed, 29 Dec 2021 14:42:00 -0500 Subject: [PATCH] readlink: eliminate duplicate code --- src/uu/readlink/src/readlink.rs | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/uu/readlink/src/readlink.rs b/src/uu/readlink/src/readlink.rs index d6dd1634a..4dc2104cc 100644 --- a/src/uu/readlink/src/readlink.rs +++ b/src/uu/readlink/src/readlink.rs @@ -78,25 +78,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 { for f in &files { let p = PathBuf::from(f); - if res_mode == ResolveMode::None { - match fs::read_link(&p) { - Ok(path) => show(&path, no_newline, use_zero), - Err(err) => { - if verbose { - show_error!("{}: errno {}", f.maybe_quote(), err.raw_os_error().unwrap()); - } - return 1; - } - } + let path_result = if res_mode == ResolveMode::None { + fs::read_link(&p) } else { - match canonicalize(&p, can_mode, res_mode) { - Ok(path) => show(&path, no_newline, use_zero), - Err(err) => { - if verbose { - show_error!("{}: errno {}", f.maybe_quote(), err.raw_os_error().unwrap()); - } - return 1; + canonicalize(&p, can_mode, res_mode) + }; + match path_result { + Ok(path) => show(&path, no_newline, use_zero), + Err(err) => { + if verbose { + show_error!("{}: errno {}", f.maybe_quote(), err.raw_os_error().unwrap()); } + return 1; } } }