mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
readlink: eliminate duplicate code
This commit is contained in:
parent
4ae838a8b2
commit
2a7831bd94
1 changed files with 10 additions and 17 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue