mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
Merge pull request #2829 from jfinkels/sync-uresult
sync: return UResult from uumain() function
This commit is contained in:
commit
8673fbaa03
1 changed files with 9 additions and 12 deletions
|
@ -9,14 +9,10 @@
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate uucore;
|
|
||||||
|
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
|
use uucore::error::{UResult, USimpleError};
|
||||||
static EXIT_ERR: i32 = 1;
|
|
||||||
|
|
||||||
static ABOUT: &str = "Synchronize cached writes to persistent storage";
|
static ABOUT: &str = "Synchronize cached writes to persistent storage";
|
||||||
pub mod options {
|
pub mod options {
|
||||||
|
@ -72,6 +68,7 @@ mod platform {
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::os::windows::prelude::*;
|
use std::os::windows::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use uucore::crash;
|
||||||
use uucore::wide::{FromWide, ToWide};
|
use uucore::wide::{FromWide, ToWide};
|
||||||
|
|
||||||
unsafe fn flush_volume(name: &str) {
|
unsafe fn flush_volume(name: &str) {
|
||||||
|
@ -164,7 +161,8 @@ fn usage() -> String {
|
||||||
format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
|
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 usage = usage();
|
||||||
|
|
||||||
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
||||||
|
@ -176,11 +174,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
for f in &files {
|
for f in &files {
|
||||||
if !Path::new(&f).exists() {
|
if !Path::new(&f).exists() {
|
||||||
crash!(
|
return Err(USimpleError::new(
|
||||||
EXIT_ERR,
|
1,
|
||||||
"cannot stat {}: No such file or directory",
|
format!("cannot stat {}: No such file or directory", f.quote()),
|
||||||
f.quote()
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +191,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
} else {
|
} else {
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
0
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> App<'static, 'static> {
|
pub fn uu_app() -> App<'static, 'static> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue