diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-02-03 19:53:50 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-02-11 03:22:56 +0100 |
commit | f1a639ea8ca400db5de0864d76a8c2f374bc2bb4 (patch) | |
tree | bc0830fb6c00551b0e4e076e5c302e8438fde4e1 /lib/core/libimagrt/src | |
parent | 19912f5e88bf0c0f1a1c521f6f5109ee6fac8cff (diff) |
Change id reporting API to return ExitCode
Because this API only errors when write!() errors occur, we can return
the exit code as an error here.
This way the user of the API can immediately exit if there was an IO
error, but the API automatically takes care of the right return value,
returning (exiting) with zero (0) if there was an "Broken pipe" error
and with one (1) otherwise, which is the expected behaviour here.
All calls to that API were changed accordingly.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib/core/libimagrt/src')
-rw-r--r-- | lib/core/libimagrt/src/runtime.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index 5fb367dc..2466fad4 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -25,6 +25,7 @@ use std::io::Stdin; use std::sync::Arc; use std::io::StdoutLock; use std::borrow::Borrow; +use std::result::Result as RResult; pub use clap::App; use clap::AppSettings; @@ -41,8 +42,10 @@ use configuration::{fetch_config, override_config, InternalConfiguration}; use logger::ImagLogger; use io::OutputProxy; +use libimagerror::exit::ExitCode; use libimagerror::errors::ErrorMsg as EM; use libimagerror::trace::*; +use libimagerror::io::ToExitCode; use libimagstore::store::Store; use libimagstore::storeid::StoreId; use libimagstore::file_abstraction::InMemoryFileAbstraction; @@ -573,14 +576,14 @@ impl<'a> Runtime<'a> { .map_err(Error::from) } - pub fn report_touched(&self, id: &StoreId) -> Result<()> { + pub fn report_touched(&self, id: &StoreId) -> RResult<(), ExitCode> { let out = ::std::io::stdout(); let mut lock = out.lock(); self.report_touched_id(id, &mut lock) } - pub fn report_all_touched<ID, I>(&self, ids: I) -> Result<()> + pub fn report_all_touched<ID, I>(&self, ids: I) -> RResult<(), ExitCode> where ID: Borrow<StoreId> + Sized, I: Iterator<Item = ID> { @@ -595,15 +598,15 @@ impl<'a> Runtime<'a> { } #[inline] - fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> Result<()> { + fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> RResult<(), ExitCode> { use std::io::Write; if self.output_is_pipe() && !self.ignore_ids { trace!("Reporting: {} to {:?}", id, output); - writeln!(output, "{}", id)?; + writeln!(output, "{}", id).to_exit_code() + } else { + Ok(()) } - - Ok(()) } } |