readlink: eliminate duplicate code
@@ -78,18 +78,12 @@ 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) {
+ canonicalize(&p, can_mode, res_mode)
+ };
+ match path_result {
Ok(path) => show(&path, no_newline, use_zero),
Err(err) => {
if verbose {
@@ -99,7 +93,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
}
}
}
- }
0
}
