From f1a639ea8ca400db5de0864d76a8c2f374bc2bb4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Feb 2019 19:53:50 +0100 Subject: 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 --- lib/core/libimagrt/src/runtime.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/core/libimagrt/src') 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(&self, ids: I) -> Result<()> + pub fn report_all_touched(&self, ids: I) -> RResult<(), ExitCode> where ID: Borrow + Sized, I: Iterator { @@ -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(()) } } -- cgit v1.2.3