Adapt to new function interface of build_entry_path()

This commit is contained in:
Matthias Beyer 2016-03-13 21:04:06 +01:00
parent 80945fcd16
commit df740ac63a
4 changed files with 61 additions and 24 deletions

View file

@ -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() {

View file

@ -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);

View file

@ -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);
})
})
});
}

View file

@ -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("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();
scmd.value_of("content")
.map(|new_content| {
*e.get_content_mut() = String::from(new_content);
debug!("New content set");
});
rt.store()
.retrieve(path)
.map(|mut locked_e| {
let mut e = locked_e.deref_mut();
*e.get_header_mut() = build_toml_header(scmd, e.get_header().clone());
debug!("New header set");
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");
})
})
});