diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-12-22 21:00:36 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-12-22 21:00:36 +0100 |
commit | 1809f4d4eff865a0a8237e8fb202d7a9c1e69b1a (patch) | |
tree | 1f2f6b26bd37ee639603ac5e3412d05a88b412aa /lib | |
parent | 3e016d901f069eb2c7a772bf71f9920533de6e10 (diff) | |
parent | 0464bfba53255814aadc35d9927c8d0fff2eb00d (diff) |
Merge branch 'report-ids-ignore-broken-pipe' into master
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/core/libimagrt/src/runtime.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index d8997a8b..a1a27c6c 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -24,7 +24,6 @@ use std::process::exit; use std::io::Stdin; use std::io::StdoutLock; use std::borrow::Borrow; -use std::result::Result as RResult; pub use clap::App; use clap::AppSettings; @@ -41,10 +40,8 @@ use crate::configuration::{fetch_config, override_config, InternalConfiguration} use crate::logger::ImagLogger; use crate::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 libimagutil::debug_result::DebugResult; @@ -522,14 +519,14 @@ impl<'a> Runtime<'a> { .map_err(Error::from) } - pub fn report_touched(&self, id: &StoreId) -> RResult<(), ExitCode> { + pub fn report_touched(&self, id: &StoreId) -> Result<()> { let out = ::std::io::stdout(); let mut lock = out.lock(); - self.report_touched_id(id, &mut lock) + self.report_touched_id(id, &mut lock).map(|_| ()) } - pub fn report_all_touched<ID, I>(&self, ids: I) -> RResult<(), ExitCode> + pub fn report_all_touched<ID, I>(&self, ids: I) -> Result<()> where ID: Borrow<StoreId> + Sized, I: Iterator<Item = ID> { @@ -537,22 +534,30 @@ impl<'a> Runtime<'a> { let mut lock = out.lock(); for id in ids { - self.report_touched_id(id.borrow(), &mut lock)?; + if !self.report_touched_id(id.borrow(), &mut lock)? { + break + } } Ok(()) } #[inline] - fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> RResult<(), ExitCode> { + fn report_touched_id(&self, id: &StoreId, output: &mut StdoutLock) -> Result<bool> { use std::io::Write; if self.output_is_pipe() && !self.ignore_ids { trace!("Reporting: {} to {:?}", id, output); - writeln!(output, "{}", id).to_exit_code() - } else { - Ok(()) + if let Err(e) = writeln!(output, "{}", id) { + return if e.kind() == std::io::ErrorKind::BrokenPipe { + Ok(false) + } else { + Err(failure::Error::from(e)) + } + } } + + Ok(true) } } |