summaryrefslogtreecommitdiff
path: root/bin/core/imag-store
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-11 19:37:52 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-02-12 21:19:48 +0100
commit3845399fb8221155adcee6994352c21d1ce696f6 (patch)
tree2b98dc75032b10e95e09c44ade2df837424374b4 /bin/core/imag-store
parentba1c6c06fac878844ac03b9bd4032067c815364b (diff)
downloadimag-3845399fb8221155adcee6994352c21d1ce696f6.zip
imag-3845399fb8221155adcee6994352c21d1ce696f6.tar.gz
Simplify implementation for new libimagerror interface
Diffstat (limited to 'bin/core/imag-store')
-rw-r--r--bin/core/imag-store/src/create.rs9
-rw-r--r--bin/core/imag-store/src/delete.rs3
-rw-r--r--bin/core/imag-store/src/dump.rs26
-rw-r--r--bin/core/imag-store/src/get.rs11
-rw-r--r--bin/core/imag-store/src/update.rs4
5 files changed, 18 insertions, 35 deletions
diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs
index 2aed5d8..492655f 100644
--- a/bin/core/imag-store/src/create.rs
+++ b/bin/core/imag-store/src/create.rs
@@ -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<()> {
diff --git a/bin/core/imag-store/src/delete.rs b/bin/core/imag-store/src/delete.rs
index 9e1254d..d90fd03 100644
--- a/bin/core/imag-store/src/delete.rs
+++ b/bin/core/imag-store/src/delete.rs
@@ -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()
diff --git a/bin/core/imag-store/src/dump.rs b/bin/core/imag-store/src/dump.rs
index e9eae4e..0de05e2 100644
--- a/bin/core/imag-store/src/dump.rs
+++ b/bin/core/imag-store/src/dump.rs
@@ -23,28 +23,16 @@ 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 {
- 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);
- }
- }
+ .map_err_trace_exit_unwrap(1)
+ .for_each(|elem| {
+ debug!("Working on {:?}", 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");
+ if let Err(_) = rt.store_backend_to_stdout().map_err_trace() {
+ error!("Loading Store IO backend failed");
exit(1);
}
}
diff --git a/bin/core/imag-store/src/get.rs b/bin/core/imag-store/src/get.rs
index bff7b67..b9324fe 100644
--- a/bin/core/imag-store/src/get.rs
+++ b/bin/core/imag-store/src/get.rs
@@ -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"),
};
}
diff --git a/bin/core/imag-store/src/update.rs b/bin/core/imag-store/src/update.rs
index 574b15e..981c808 100644
--- a/bin/core/imag-store/src/update.rs
+++ b/bin/core/imag-store/src/update.rs
@@ -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)