Simplify implementation for new libimagerror interface
This commit is contained in:
parent
ba1c6c06fa
commit
3845399fb8
5 changed files with 18 additions and 35 deletions
|
@ -30,7 +30,7 @@ use toml::Value;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagerror::trace::trace_error_exit;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagutil::debug_result::*;
|
use libimagutil::debug_result::*;
|
||||||
|
|
||||||
use error::StoreError;
|
use error::StoreError;
|
||||||
|
@ -48,7 +48,7 @@ pub fn create(rt: &Runtime) {
|
||||||
let path = scmd.value_of("path").unwrap();
|
let path = scmd.value_of("path").unwrap();
|
||||||
let path = PathBuf::from(path);
|
let path = PathBuf::from(path);
|
||||||
let store = Some(rt.store().path().clone());
|
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);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
|
@ -65,10 +65,7 @@ pub fn create(rt: &Runtime) {
|
||||||
create_with_content_and_header(rt, &path, String::new(),
|
create_with_content_and_header(rt, &path, String::new(),
|
||||||
Entry::default_header())
|
Entry::default_header())
|
||||||
}
|
}
|
||||||
.unwrap_or_else(|e| {
|
.map_err_trace_exit_unwrap(1);
|
||||||
error!("Error building Entry");
|
|
||||||
trace_error_exit(&e, 1);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {
|
fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Result<()> {
|
||||||
|
|
|
@ -21,7 +21,6 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::trace::trace_error_exit;
|
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
use libimagutil::warn_result::*;
|
use libimagutil::warn_result::*;
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ pub fn delete(rt: &Runtime) {
|
||||||
let id = scmd.value_of("id").unwrap(); // safe by clap
|
let id = scmd.value_of("id").unwrap(); // safe by clap
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let store = Some(rt.store().path().clone());
|
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);
|
debug!("Deleting file at {:?}", id);
|
||||||
|
|
||||||
let _ = rt.store()
|
let _ = rt.store()
|
||||||
|
|
|
@ -23,28 +23,16 @@ use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::*;
|
use libimagerror::trace::*;
|
||||||
|
|
||||||
pub fn dump(rt: &mut Runtime) {
|
pub fn dump(rt: &mut Runtime) {
|
||||||
let cachingres = rt
|
rt.store()
|
||||||
.store()
|
|
||||||
.entries()
|
.entries()
|
||||||
.map_err_trace()
|
.map_err_trace_exit_unwrap(1)
|
||||||
.map(|iter| {
|
.for_each(|elem| {
|
||||||
for elem in iter {
|
debug!("Working on {:?}", elem);
|
||||||
debug!("Working on {:?}", elem);
|
rt.store().get(elem).map_err_trace_exit_unwrap(1);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Ok(_) = cachingres {
|
if let Err(_) = rt.store_backend_to_stdout().map_err_trace() {
|
||||||
if let Err(_) = rt.store_backend_to_stdout().map_err_trace() {
|
error!("Loading Store IO backend failed");
|
||||||
error!("Loading Store IO backend failed");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error!("Loading entries failed");
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::trace_error_exit;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
use retrieve::print_entry;
|
use retrieve::print_entry;
|
||||||
|
@ -31,13 +31,12 @@ pub fn get(rt: &Runtime) {
|
||||||
let id = scmd.value_of("id").unwrap(); // safe by clap
|
let id = scmd.value_of("id").unwrap(); // safe by clap
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let store = Some(rt.store().path().clone());
|
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);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
let _ = match rt.store().get(path) {
|
let _ = match rt.store().get(path).map_err_trace_exit_unwrap(1) {
|
||||||
Ok(Some(entry)) => print_entry(rt, scmd, entry),
|
Some(entry) => print_entry(rt, scmd, entry),
|
||||||
Ok(None) => info!("No entry found"),
|
None => info!("No entry found"),
|
||||||
Err(e) => trace_error_exit(&e, 1),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ use std::ops::DerefMut;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
use libimagerror::trace::trace_error_exit;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagstore::storeid::StoreId;
|
use libimagstore::storeid::StoreId;
|
||||||
|
|
||||||
use util::build_toml_header;
|
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 id = scmd.value_of("id").unwrap(); // Safe by clap
|
||||||
let path = PathBuf::from(id);
|
let path = PathBuf::from(id);
|
||||||
let store = Some(rt.store().path().clone());
|
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()
|
let _ = rt.store()
|
||||||
.retrieve(path)
|
.retrieve(path)
|
||||||
|
|
Loading…
Reference in a new issue