From 49dca9adcb35bf503e4efbbaf8bb7444c28cc879 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sun, 2 Jan 2022 19:59:15 -0500 Subject: [PATCH] realpath: return UResult from uumain() function --- src/uu/realpath/src/realpath.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/uu/realpath/src/realpath.rs b/src/uu/realpath/src/realpath.rs index d13aed6c7..de8833341 100644 --- a/src/uu/realpath/src/realpath.rs +++ b/src/uu/realpath/src/realpath.rs @@ -17,6 +17,7 @@ use std::{ }; use uucore::{ display::{print_verbatim, Quotable}, + error::{FromIo, UResult}, fs::{canonicalize, MissingHandling, ResolveMode}, }; @@ -36,7 +37,8 @@ fn usage() -> String { format!("{0} [OPTION]... FILE...", uucore::execution_phrase()) } -pub fn uumain(args: impl uucore::Args) -> i32 { +#[uucore_procs::gen_uumain] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { let usage = usage(); let matches = uu_app().usage(&usage[..]).get_matches_from(args); @@ -60,16 +62,16 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } else { MissingHandling::Normal }; - let mut retcode = 0; for path in &paths { - if let Err(e) = resolve_path(path, strip, zero, logical, can_mode) { - if !quiet { - show_error!("{}: {}", path.maybe_quote(), e); - } - retcode = 1 - }; + let result = resolve_path(path, strip, zero, logical, can_mode); + if !quiet { + show_if_err!(result.map_err_context(|| path.maybe_quote().to_string())); + } } - retcode + // Although we return `Ok`, it is possible that a call to + // `show!()` above has set the exit code for the program to a + // non-zero integer. + Ok(()) } pub fn uu_app() -> App<'static, 'static> {