~matthiasbeyer/imag

1809f4d4eff865a0a8237e8fb202d7a9c1e69b1a — Matthias Beyer 1 year, 9 months ago 3e016d9 + 0464bfb
Merge branch 'report-ids-ignore-broken-pipe' into master

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
M bin/core/imag-category/src/lib.rs => bin/core/imag-category/src/lib.rs +1 -1
@@ 165,7 165,7 @@ fn create_category(rt: &Runtime) -> Result<()> {
    let name = scmd.value_of("create-category-name").map(String::from).unwrap(); // safed by clap
    rt.store()
        .create_category(&name)
        .and_then(|e| rt.report_touched(e.get_location()).map_err(Error::from))
        .and_then(|e| rt.report_touched(e.get_location()))
}

fn delete_category(rt: &Runtime) -> Result<()> {

M bin/core/imag-gps/src/lib.rs => bin/core/imag-gps/src/lib.rs +3 -3
@@ 144,7 144,7 @@ fn add(rt: &Runtime) -> Result<()> {
                .ok_or_else(|| format_err!("No such entry: {}", id))?
                .set_coordinates(c.clone())?;

            rt.report_touched(&id).map_err(Error::from)
            rt.report_touched(&id)
        })
        .collect()
}


@@ 170,7 170,7 @@ fn remove(rt: &Runtime) -> Result<()> {
                writeln!(rt.stdout(), "{}", removed_value)?;
            }

            rt.report_touched(&id).map_err(Error::from)
            rt.report_touched(&id)
        })
        .collect()
}


@@ 194,7 194,7 @@ fn get(rt: &Runtime) -> Result<()> {

            writeln!(stdout, "{}", value)?;

            rt.report_touched(&id).map_err(Error::from)
            rt.report_touched(&id)
        })
        .collect()
}

M bin/core/imag-grep/src/lib.rs => bin/core/imag-grep/src/lib.rs +1 -2
@@ 48,7 48,6 @@ use std::io::Write;

use regex::Regex;
use clap::App;
use failure::Error;
use failure::Fallible as Result;
use failure::err_msg;
use resiter::AndThen;


@@ 154,6 153,6 @@ fn show(rt: &Runtime, e: &Entry, re: &Regex, opts: &Options, count: &mut usize) 
        *count += 1;
    }

    rt.report_touched(e.get_location()).map_err(Error::from)
    rt.report_touched(e.get_location())
}


M bin/core/imag-header/src/lib.rs => bin/core/imag-header/src/lib.rs +6 -6
@@ 180,7 180,7 @@ fn has<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()>
            if !rt.output_is_pipe() {
                writeln!(output, "{}", entry.get_location())?;
            }
            rt.report_touched(entry.get_location()).map_err(Error::from)
            rt.report_touched(entry.get_location())
        } else {
            Ok(())
        }


@@ 203,7 203,7 @@ fn hasnt<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()>
            if !rt.output_is_pipe() {
                writeln!(output, "{}", entry.get_location())?;
            }
            rt.report_touched(entry.get_location()).map_err(Error::from)
            rt.report_touched(entry.get_location())
        }
    })
    .collect()


@@ 256,7 256,7 @@ fn int<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()>
        }
    })
    .filter_map_ok(|(b, e)| if b { Some(e) } else { None })
    .and_then_ok(|entry| rt.report_touched(entry.get_location()).map_err(Error::from))
    .and_then_ok(|entry| rt.report_touched(entry.get_location()))
    .collect()
}



@@ 294,7 294,7 @@ fn float<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()>
        }
    })
    .filter_map_ok(|(b, e)| if b { Some(e) } else { None })
    .and_then_ok(|entry| rt.report_touched(entry.get_location()).map_err(Error::from))
    .and_then_ok(|entry| rt.report_touched(entry.get_location()))
    .collect()
}



@@ 320,7 320,7 @@ fn string<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()>
        }
    })
    .filter_map_ok(|(b, e)| if b { Some(e) } else { None })
    .and_then_ok(|entry| rt.report_touched(entry.get_location()).map_err(Error::from))
    .and_then_ok(|entry| rt.report_touched(entry.get_location()))
    .collect()
}



@@ 342,7 342,7 @@ fn boolean<'a, 'e, I>(rt: &Runtime, mtch: &ArgMatches<'a>, iter: I) -> Result<()
        }
    })
    .filter_map_ok(|(b, e)| if b { Some(e) } else { None })
    .and_then_ok(|entry| rt.report_touched(entry.get_location()).map_err(Error::from))
    .and_then_ok(|entry| rt.report_touched(entry.get_location()))
    .collect()
}


M bin/core/imag-id-in-collection/src/lib.rs => bin/core/imag-id-in-collection/src/lib.rs +1 -2
@@ 52,7 52,6 @@ use std::io::Write;

use filters::filter::Filter;
use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
use clap::App;



@@ 113,7 112,7 @@ impl ImagApplication for ImagIdInCollection {
                    writeln!(stdout, "{}", id)?;
                }

                rt.report_touched(&id).map_err(Error::from)
                rt.report_touched(&id)
            })
            .collect()
    }

M bin/core/imag-ids/src/lib.rs => bin/core/imag-ids/src/lib.rs +1 -2
@@ 52,7 52,6 @@ use std::io::Write;

use failure::Fallible as Result;
use failure::err_msg;
use failure::Error;
use resiter::Map;
use resiter::AndThen;
use clap::App;


@@ 92,7 91,7 @@ impl ImagApplication for ImagIds {
                    }
                }

                rt.report_touched(&id).map_err(Error::from)
                rt.report_touched(&id)
            })
            .collect::<Result<()>>()
        };

M bin/core/imag-link/src/lib.rs => bin/core/imag-link/src/lib.rs +5 -6
@@ 72,7 72,6 @@ use libimagstore::storeid::StoreId;

use url::Url;
use failure::Fallible as Result;
use failure::Error;
use clap::App;

mod ui;


@@ 179,7 178,7 @@ fn link_from_to<'a, I>(rt: &'a Runtime, from: &'a str, to: I) -> Result<()>
        info!("Ok: {} -> {}", from, entry);
    }

    rt.report_touched(from_entry.get_location()).map_err(Error::from)
    rt.report_touched(from_entry.get_location())
}

fn remove_linking(rt: &Runtime) -> Result<()> {


@@ 198,7 197,7 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
        .map(|id| match rt.store().get(id.clone())? {
            Some(mut to_entry) => {
                to_entry.remove_link(&mut from)?;
                rt.report_touched(to_entry.get_location()).map_err(Error::from)
                rt.report_touched(to_entry.get_location())
            },

            None => {


@@ 217,7 216,7 @@ fn remove_linking(rt: &Runtime) -> Result<()> {
        })
        .collect::<Result<Vec<_>>>()?;

    rt.report_touched(from.get_location()).map_err(Error::from)
    rt.report_touched(from.get_location())
}

fn unlink(rt: &Runtime) -> Result<()> {


@@ 231,7 230,7 @@ fn unlink(rt: &Runtime) -> Result<()> {
                .ok_or_else(|| format_err!("No entry for {}", id))?
                .unlink(rt.store())?;

            rt.report_touched(&id).map_err(Error::from)
            rt.report_touched(&id)
        })
        .collect()
}


@@ 280,7 279,7 @@ fn list_linkings(rt: &Runtime) -> Result<()> {
                    .collect::<Result<Vec<_>>>()?;
            }

            rt.report_touched(entry.get_location()).map_err(Error::from)
            rt.report_touched(entry.get_location())
        })
        .collect::<Result<Vec<_>>>()?;


M bin/core/imag-ref/src/lib.rs => bin/core/imag-ref/src/lib.rs +2 -2
@@ 131,7 131,7 @@ fn deref(rt: &Runtime) -> Result<()> {
                    .ok_or_else(|| Error::from(::libimagerror::errors::ErrorMsg::UTF8Error))
                    .and_then(|s| writeln!(outlock, "{}", s).map_err(Error::from))?;

                    rt.report_touched(&id).map_err(Error::from)
                    rt.report_touched(&id)
                },
                None => Err(format_err!("No entry for id '{}' found", id))
            }


@@ 193,7 193,7 @@ fn list_dead(rt: &Runtime) -> Result<()> {
                                unimplemented!()
                            }?;

                            rt.report_touched(entry.get_location()).map_err(Error::from)
                            rt.report_touched(entry.get_location())
                        } else {
                            Ok(())
                        }

M bin/core/imag-store/src/create.rs => bin/core/imag-store/src/create.rs +1 -2
@@ 26,7 26,6 @@ use std::io::Read;
use clap::ArgMatches;
use toml::Value;
use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;

use libimagrt::runtime::Runtime;


@@ 59,7 58,7 @@ pub fn create(rt: &Runtime) -> Result<()> {
        create_with_content_and_header(rt, &path, String::new(), Entry::default_header())?;
    }

    rt.report_touched(&path).map_err(Error::from)
    rt.report_touched(&path)
}

fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {

M bin/core/imag-store/src/get.rs => bin/core/imag-store/src/get.rs +1 -2
@@ 20,7 20,6 @@
use std::path::PathBuf;

use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;

use libimagrt::runtime::Runtime;


@@ 40,7 39,7 @@ pub fn get(rt: &Runtime) -> Result<()> {
        None        => Err(err_msg("No entry found")),
        Some(entry) => {
            print_entry(rt, scmd, entry)?;
            rt.report_touched(&path).map_err(Error::from)
            rt.report_touched(&path)
        },
    }
}

M bin/core/imag-store/src/retrieve.rs => bin/core/imag-store/src/retrieve.rs +1 -2
@@ 21,7 21,6 @@ use std::path::PathBuf;
use std::io::Write;

use failure::Fallible as Result;
use failure::Error;
use clap::ArgMatches;

use libimagstore::store::FileLockEntry;


@@ 39,7 38,7 @@ pub fn retrieve(rt: &Runtime) -> Result<()> {
        .retrieve(path.clone())
        .and_then(|e| print_entry(rt, scmd, e))?;

    rt.report_touched(&path).map_err(Error::from)
    rt.report_touched(&path)
}

pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) -> Result<()> {

M bin/core/imag-store/src/update.rs => bin/core/imag-store/src/update.rs +1 -2
@@ 21,7 21,6 @@ use std::ops::DerefMut;
use std::path::PathBuf;

use failure::Fallible as Result;
use failure::Error;

use libimagrt::runtime::Runtime;
use libimagstore::storeid::StoreId;


@@ 49,7 48,7 @@ pub fn update(rt: &Runtime) -> Result<()> {
                debug!("New header set");
            }

            rt.report_touched(locked_e.get_location()).map_err(Error::from)
            rt.report_touched(locked_e.get_location())
        })
}


M bin/core/imag-tag/src/lib.rs => bin/core/imag-tag/src/lib.rs +4 -5
@@ 62,7 62,6 @@ extern crate env_logger;
use std::io::Write;

use failure::Fallible as Result;
use failure::Error;
use failure::err_msg;
use resiter::AndThen;
use resiter::Map;


@@ 142,7 141,7 @@ impl ImagApplication for ImagTag {
                            }
                            Ok(e)
                        })
                        .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from))
                        .and_then_ok(|e| rt.report_touched(e.get_location()))
                        .collect::<Result<Vec<_>>>()
                        .map(|_| ())
                },


@@ 181,7 180,7 @@ impl ImagApplication for ImagTag {
                            }
                            Ok(e)
                        })
                        .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from))
                        .and_then_ok(|e| rt.report_touched(e.get_location()))
                        .collect::<Result<Vec<_>>>()
                        .map(|_| ())
                },


@@ 251,7 250,7 @@ fn alter(rt: &Runtime, path: StoreId, add: Option<Vec<Tag>>, rem: Option<Vec<Tag
        },
    }

    rt.report_touched(&path).map_err(Error::from)
    rt.report_touched(&path)
}

fn list(path: StoreId, rt: &Runtime) -> Result<()> {


@@ 288,7 287,7 @@ fn list(path: StoreId, rt: &Runtime) -> Result<()> {
        writeln!(rt.stdout(), "{}", tags.join(", "))?;
    }

    rt.report_touched(&path).map_err(Error::from)
    rt.report_touched(&path)
}

/// Get the tags which should be added from the commandline

M bin/core/imag-view/src/lib.rs => bin/core/imag-view/src/lib.rs +2 -3
@@ 56,7 56,6 @@ use std::process::Command;

use handlebars::Handlebars;
use toml_query::read::TomlValueReadTypeExt;
use failure::Error;
use failure::err_msg;
use failure::Fallible as Result;
use resiter::AndThen;


@@ 186,7 185,7 @@ impl ImagApplication for ImagView {
                    viewer.view_entry(&entry, &mut outlock)?;

                    i += 1;
                    rt.report_touched(entry.get_location()).map_err(Error::from)
                    rt.report_touched(entry.get_location())
                })
                .collect()
            } else {


@@ 217,7 216,7 @@ impl ImagApplication for ImagView {
                    viewer.view_entry(&entry, &mut outlock)?;

                    i += 1;
                    rt.report_touched(entry.get_location()).map_err(Error::from)
                    rt.report_touched(entry.get_location())
                })
                .collect()
            }

M bin/domain/imag-calendar/src/lib.rs => bin/domain/imag-calendar/src/lib.rs +3 -3
@@ 168,7 168,7 @@ fn import(rt: &Runtime) -> Result<()> {
        .collect::<Result<Vec<_>>>()?
        .into_iter()
        .flatten()
        .and_then_ok(|fle| rt.report_touched(fle.get_location()).map_err(Error::from));
        .and_then_ok(|fle| rt.report_touched(fle.get_location()));

    if do_fail {
        iter.collect()


@@ 256,7 256,7 @@ fn list(rt: &Runtime) -> Result<()> {
                })
                .collect::<Result<Vec<_>>>()?;

            rt.report_touched(parsed_entry.get_entry().get_location()).map_err(Error::from)
            rt.report_touched(parsed_entry.get_entry().get_location())
        })
        .collect()
}


@@ 303,7 303,7 @@ fn show(rt: &Runtime) -> Result<()> {
                })
                .collect::<Result<Vec<_>>>()?;

            rt.report_touched(parsed_entry.get_entry().get_location()).map_err(Error::from)
            rt.report_touched(parsed_entry.get_entry().get_location())
        })
        .collect()
}

M bin/domain/imag-todo/src/lib.rs => bin/domain/imag-todo/src/lib.rs +4 -4
@@ 222,7 222,7 @@ fn create(rt: &Runtime) -> Result<()> {
        entry.edit_content(&rt)?;
    }

    rt.report_touched(entry.get_location()).map_err(Error::from)
    rt.report_touched(entry.get_location())
}

fn mark(rt: &Runtime) -> Result<()> {


@@ 233,7 233,7 @@ fn mark(rt: &Runtime) -> Result<()> {
            .map(Ok)
            .into_get_iter(rt.store())
            .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
            .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
            .and_then_ok(|e| rt.report_touched(e.get_location()).map(|_| e))
            .and_then_ok(|mut e| e.set_status(status.clone()))
            .collect()
    }


@@ 339,7 339,7 @@ fn list_todos(rt: &Runtime, matcher: &StatusMatcher, show_hidden: bool) -> Resul
                    }
                }

                rt.report_touched(entry.get_location()).map_err(Error::from)
                rt.report_touched(entry.get_location())
            })
            .collect()
    };


@@ 453,7 453,7 @@ fn show(rt: &Runtime) -> Result<()> {
        .map(Ok)
        .into_get_iter(rt.store())
        .map_inner_ok_or_else(|| err_msg("Did not find one entry"))
        .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from).map(|_| e))
        .and_then_ok(|e| rt.report_touched(e.get_location()).map(|_| e))
        .collect::<Result<Vec<_>>>()?
        .into_iter();


M lib/core/libimagrt/src/runtime.rs => lib/core/libimagrt/src/runtime.rs +16 -11
@@ 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)
    }
}