~matthiasbeyer/imag

ad7d8bf63c49905a341039eac6c96d4f7fa33f29 — Matthias Beyer 1 year, 1 month ago 91901fa
Optimize: Stop iteration for viewing on broken pipe error

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2 files changed, 10 insertions(+), 2 deletions(-)

M lib/entry/libimagentryview/src/lib.rs
M lib/entry/libimagentryview/src/viewer.rs
M lib/entry/libimagentryview/src/lib.rs => lib/entry/libimagentryview/src/lib.rs +1 -0
@@ 37,6 37,7 @@
    while_true,
)]

#[macro_use] extern crate log;
extern crate toml;
extern crate textwrap;
extern crate failure;

M lib/entry/libimagentryview/src/viewer.rs => lib/entry/libimagentryview/src/viewer.rs +9 -2
@@ 130,8 130,15 @@ impl<'a, I, V, W, F, T> Iterator for ViewIter<'a, I, V, W, F, T>
    fn next(&mut self) -> Option<Self::Item> {
        if let Some(next) = self.inner.next() {
            if let Some(entry) = (self.func)(&next) {
                if let Err(e) = self.viewer.view_entry(&entry, self.sink) {
                    return Some(Err(e).map_err(failure::Error::from))
                let r = self.viewer.view_entry(&entry, self.sink);
                trace!("Viewing resulted in {:?}", r);
                match r {
                    Ok(_) => { /* nothing */ },
                    Err(crate::error::Error::Io(ref e)) if e.kind() == std::io::ErrorKind::BrokenPipe => {
                        trace!("Stopping iteration, because of broken pipe error!");
                        return None
                    },
                    Err(e) => return Some(Err(failure::Error::from(e)))
                }
            }