Simplify implementation for new libimagerror interface

This commit is contained in:
Matthias Beyer 2018-02-11 19:37:52 +01:00
parent ba1c6c06fa
commit 3845399fb8
5 changed files with 18 additions and 35 deletions

View file

@ -30,7 +30,7 @@ use toml::Value;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
use libimagstore::storeid::StoreId;
use libimagerror::trace::trace_error_exit;
use libimagerror::trace::MapErrTrace;
use libimagutil::debug_result::*;
use error::StoreError;
@ -48,7 +48,7 @@ pub fn create(rt: &Runtime) {
let path = scmd.value_of("path").unwrap();
let path = PathBuf::from(path);
let store = Some(rt.store().path().clone());
let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
debug!("path = {:?}", path);
@ -65,10 +65,7 @@ pub fn create(rt: &Runtime) {
create_with_content_and_header(rt, &path, String::new(),
Entry::default_header())
}
.unwrap_or_else(|e| {
error!("Error building Entry");
trace_error_exit(&e, 1);
})
.map_err_trace_exit_unwrap(1);
}
fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {

View file

@ -21,7 +21,6 @@ use std::path::PathBuf;
use libimagrt::runtime::Runtime;
use libimagerror::trace::MapErrTrace;
use libimagerror::trace::trace_error_exit;
use libimagstore::storeid::StoreId;
use libimagutil::warn_result::*;
@ -30,7 +29,7 @@ pub fn delete(rt: &Runtime) {
let id = scmd.value_of("id").unwrap(); // safe by clap
let path = PathBuf::from(id);
let store = Some(rt.store().path().clone());
let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
debug!("Deleting file at {:?}", id);
let _ = rt.store()

View file

@ -23,29 +23,17 @@ use libimagrt::runtime::Runtime;
use libimagerror::trace::*;
pub fn dump(rt: &mut Runtime) {
let cachingres = rt
.store()
rt.store()
.entries()
.map_err_trace()
.map(|iter| {
for elem in iter {
.map_err_trace_exit_unwrap(1)
.for_each(|elem| {
debug!("Working on {:?}", elem);
if let Ok(_) = rt.store().get(elem.clone()).map_err_dbg_trace() {
info!("Loading entry at {:?} succeeded", elem);
} else {
error!("Loading entry at {:?} failed", elem);
}
}
rt.store().get(elem).map_err_trace_exit_unwrap(1);
});
if let Ok(_) = cachingres {
if let Err(_) = rt.store_backend_to_stdout().map_err_trace() {
error!("Loading Store IO backend failed");
exit(1);
}
} else {
error!("Loading entries failed");
exit(1);
}
}

View file

@ -20,7 +20,7 @@
use std::path::PathBuf;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error_exit;
use libimagerror::trace::MapErrTrace;
use libimagstore::storeid::StoreId;
use retrieve::print_entry;
@ -31,13 +31,12 @@ pub fn get(rt: &Runtime) {
let id = scmd.value_of("id").unwrap(); // safe by clap
let path = PathBuf::from(id);
let store = Some(rt.store().path().clone());
let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
debug!("path = {:?}", path);
let _ = match rt.store().get(path) {
Ok(Some(entry)) => print_entry(rt, scmd, entry),
Ok(None) => info!("No entry found"),
Err(e) => trace_error_exit(&e, 1),
let _ = match rt.store().get(path).map_err_trace_exit_unwrap(1) {
Some(entry) => print_entry(rt, scmd, entry),
None => info!("No entry found"),
};
}

View file

@ -21,7 +21,7 @@ use std::ops::DerefMut;
use std::path::PathBuf;
use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error_exit;
use libimagerror::trace::MapErrTrace;
use libimagstore::storeid::StoreId;
use util::build_toml_header;
@ -31,7 +31,7 @@ pub fn update(rt: &Runtime) {
let id = scmd.value_of("id").unwrap(); // Safe by clap
let path = PathBuf::from(id);
let store = Some(rt.store().path().clone());
let path = StoreId::new(store, path).unwrap_or_else(|e| trace_error_exit(&e, 1));
let path = StoreId::new(store, path).map_err_trace_exit_unwrap(1);
let _ = rt.store()
.retrieve(path)