From 4e16717c22c93e315cbba0ce28d27a1c3ce5fd6a Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Fri, 31 Dec 2021 13:59:20 -0500 Subject: [PATCH 1/2] sync: return UResult from uumain() function --- src/uu/sync/src/sync.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index d6a21f280..9e5116a8f 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -9,14 +9,10 @@ extern crate libc; -#[macro_use] -extern crate uucore; - use clap::{crate_version, App, Arg}; use std::path::Path; use uucore::display::Quotable; - -static EXIT_ERR: i32 = 1; +use uucore::error::{UResult, USimpleError}; static ABOUT: &str = "Synchronize cached writes to persistent storage"; pub mod options { @@ -164,7 +160,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); @@ -176,11 +173,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 { for f in &files { if !Path::new(&f).exists() { - crash!( - EXIT_ERR, - "cannot stat {}: No such file or directory", - f.quote() - ); + return Err(USimpleError::new( + 1, + format!("cannot stat {}: No such file or directory", f.quote()), + )); } } @@ -194,7 +190,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } else { sync(); } - 0 + Ok(()) } pub fn uu_app() -> App<'static, 'static> { From 1ead016f3531abcc5a04f22db81fcf8ba23a961f Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Fri, 31 Dec 2021 14:28:27 -0500 Subject: [PATCH 2/2] fixup! sync: return UResult from uumain() function --- src/uu/sync/src/sync.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uu/sync/src/sync.rs b/src/uu/sync/src/sync.rs index 9e5116a8f..4e6bb7d27 100644 --- a/src/uu/sync/src/sync.rs +++ b/src/uu/sync/src/sync.rs @@ -68,6 +68,7 @@ mod platform { use std::mem; use std::os::windows::prelude::*; use std::path::Path; + use uucore::crash; use uucore::wide::{FromWide, ToWide}; unsafe fn flush_volume(name: &str) {