diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-03-13 21:04:06 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-03-19 14:48:09 +0100 |
commit | df740ac63a2eae960321195bf405e37a0c0ccda9 (patch) | |
tree | 345f8bdba5df504a94c93798eb9ebeceb7f4b72a /imag-store/src | |
parent | 80945fcd16f053b90e387fc4fd74d978216486e6 (diff) |
Adapt to new function interface of build_entry_path()
Diffstat (limited to 'imag-store/src')
-rw-r--r-- | imag-store/src/create.rs | 8 | ||||
-rw-r--r-- | imag-store/src/delete.rs | 10 | ||||
-rw-r--r-- | imag-store/src/retrieve.rs | 30 | ||||
-rw-r--r-- | imag-store/src/update.rs | 41 |
4 files changed, 63 insertions, 26 deletions
diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs index 5306ad62..9d90f642 100644 --- a/imag-store/src/create.rs +++ b/imag-store/src/create.rs @@ -14,6 +14,7 @@ use libimagrt::runtime::Runtime; use libimagstore::store::Entry; use libimagstore::store::EntryHeader; use libimagstore::storeid::build_entry_path; +use libimagutil::trace::trace_error; use error::StoreError; use error::StoreErrorKind; @@ -35,7 +36,12 @@ pub fn create(rt: &Runtime) { exit(1); } - let path = build_entry_path(rt, path.unwrap()); + let path = build_entry_path(rt.store(), path.unwrap()); + if path.is_err() { + trace_error(&path.err().unwrap()); + exit(1); + } + let path = path.unwrap(); debug!("path = {:?}", path); if scmd.subcommand_matches("entry").is_some() { diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index 182dad49..71bf0f91 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use libimagstore::storeid::build_entry_path; use libimagrt::runtime::Runtime; +use libimagutil::trace::trace_error; pub fn delete(rt: &Runtime) { use std::process::exit; @@ -11,9 +12,16 @@ pub fn delete(rt: &Runtime) { .map(|sub| { sub.value_of("id") .map(|id| { + let path = build_entry_path(rt.store(), id); + if path.is_err() { + trace_error(&path.err().unwrap()); + exit(1); + } + let path = path.unwrap(); debug!("Deleting file at {:?}", id); + rt.store() - .delete(build_entry_path(rt, id)) + .delete(path) .map_err(|e| { warn!("Error: {:?}", e); exit(1); diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index 6a00dfc2..c2c2764a 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -1,6 +1,7 @@ use std::path::PathBuf; use std::ops::Deref; use std::fmt::Display; +use std::process::exit; use clap::ArgMatches; use toml::Value; @@ -8,22 +9,31 @@ use toml::Value; use libimagstore::store::FileLockEntry; use libimagstore::storeid::build_entry_path; use libimagrt::runtime::Runtime; +use libimagutil::trace::trace_error; pub fn retrieve(rt: &Runtime) { rt.cli() .subcommand_matches("retrieve") .map(|scmd| { - let path = scmd.value_of("id").map(|id| build_entry_path(rt, id)).unwrap(); - debug!("path = {:?}", path); - rt.store() - // "id" must be present, enforced via clap spec - .retrieve(path) - .map(|e| print_entry(rt, scmd, e)) - .map_err(|e| { - debug!("No entry."); - debug!("{}", e); - }) + scmd.value_of("id") + .map(|id| { + let path = build_entry_path(rt.store(), id); + if path.is_err() { + trace_error(&path.err().unwrap()); + exit(1); + } + let path = path.unwrap(); + debug!("path = {:?}", path); + rt.store() + // "id" must be present, enforced via clap spec + .retrieve(path) + .map(|e| print_entry(rt, scmd, e)) + .map_err(|e| { + debug!("No entry."); + debug!("{}", e); + }) + }) }); } diff --git a/imag-store/src/update.rs b/imag-store/src/update.rs index 2a017c94..d37da1c2 100644 --- a/imag-store/src/update.rs +++ b/imag-store/src/update.rs @@ -1,27 +1,40 @@ use std::path::PathBuf; use std::ops::DerefMut; +use std::process::exit; use libimagrt::runtime::Runtime; -use util::build_entry_path; +use libimagstore::storeid::build_entry_path; +use libimagutil::trace::trace_error; + use util::build_toml_header; pub fn update(rt: &Runtime) { rt.cli() .subcommand_matches("update") .map(|scmd| { - rt.store() - .retrieve(scmd.value_of("id").map(|id| build_entry_path(rt, id)).unwrap()) - .map(|mut locked_e| { - let mut e = locked_e.deref_mut(); - - scmd.value_of("content") - .map(|new_content| { - *e.get_content_mut() = String::from(new_content); - debug!("New content set"); - }); - - *e.get_header_mut() = build_toml_header(scmd, e.get_header().clone()); - debug!("New header set"); + scmd.value_of("id") + .map(|id| { + let path = build_entry_path(rt.store(), id); + if path.is_err() { + trace_error(&path.err().unwrap()); + exit(1); + } + let path = path.unwrap(); + + rt.store() + .retrieve(path) + .map(|mut locked_e| { + let mut e = locked_e.deref_mut(); + + scmd.value_of("content") + .map(|new_content| { + *e.get_content_mut() = String::from(new_content); + debug!("New content set"); + }); + + *e.get_header_mut() = build_toml_header(scmd, e.get_header().clone()); + debug!("New header set"); + }) }) }); |