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::Entry;
use libimagstore::store::EntryHeader; use libimagstore::store::EntryHeader;
use libimagstore::storeid::build_entry_path; use libimagstore::storeid::build_entry_path;
use libimagutil::trace::trace_error;
use error::StoreError; use error::StoreError;
use error::StoreErrorKind; use error::StoreErrorKind;
@ -35,7 +36,12 @@ pub fn create(rt: &Runtime) {
exit(1); 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); debug!("path = {:?}", path);
if scmd.subcommand_matches("entry").is_some() { if scmd.subcommand_matches("entry").is_some() {

View file

@ -2,6 +2,7 @@ use std::path::PathBuf;
use libimagstore::storeid::build_entry_path; use libimagstore::storeid::build_entry_path;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagutil::trace::trace_error;
pub fn delete(rt: &Runtime) { pub fn delete(rt: &Runtime) {
use std::process::exit; use std::process::exit;
@ -11,9 +12,16 @@ pub fn delete(rt: &Runtime) {
.map(|sub| { .map(|sub| {
sub.value_of("id") sub.value_of("id")
.map(|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); debug!("Deleting file at {:?}", id);
rt.store() rt.store()
.delete(build_entry_path(rt, id)) .delete(path)
.map_err(|e| { .map_err(|e| {
warn!("Error: {:?}", e); warn!("Error: {:?}", e);
exit(1); exit(1);

View file

@ -1,6 +1,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::ops::Deref; use std::ops::Deref;
use std::fmt::Display; use std::fmt::Display;
use std::process::exit;
use clap::ArgMatches; use clap::ArgMatches;
use toml::Value; use toml::Value;
@ -8,22 +9,31 @@ use toml::Value;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagstore::storeid::build_entry_path; use libimagstore::storeid::build_entry_path;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagutil::trace::trace_error;
pub fn retrieve(rt: &Runtime) { pub fn retrieve(rt: &Runtime) {
rt.cli() rt.cli()
.subcommand_matches("retrieve") .subcommand_matches("retrieve")
.map(|scmd| { .map(|scmd| {
let path = scmd.value_of("id").map(|id| build_entry_path(rt, id)).unwrap(); scmd.value_of("id")
debug!("path = {:?}", path); .map(|id| {
rt.store() let path = build_entry_path(rt.store(), id);
// "id" must be present, enforced via clap spec if path.is_err() {
.retrieve(path) trace_error(&path.err().unwrap());
.map(|e| print_entry(rt, scmd, e)) exit(1);
.map_err(|e| { }
debug!("No entry."); let path = path.unwrap();
debug!("{}", e); 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::path::PathBuf;
use std::ops::DerefMut; use std::ops::DerefMut;
use std::process::exit;
use libimagrt::runtime::Runtime; 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; use util::build_toml_header;
pub fn update(rt: &Runtime) { pub fn update(rt: &Runtime) {
rt.cli() rt.cli()
.subcommand_matches("update") .subcommand_matches("update")
.map(|scmd| { .map(|scmd| {
rt.store() scmd.value_of("id")
.retrieve(scmd.value_of("id").map(|id| build_entry_path(rt, id)).unwrap()) .map(|id| {
.map(|mut locked_e| { let path = build_entry_path(rt.store(), id);
let mut e = locked_e.deref_mut(); if path.is_err() {
trace_error(&path.err().unwrap());
exit(1);
}
let path = path.unwrap();
scmd.value_of("content") rt.store()
.map(|new_content| { .retrieve(path)
*e.get_content_mut() = String::from(new_content); .map(|mut locked_e| {
debug!("New content set"); let mut e = locked_e.deref_mut();
});
*e.get_header_mut() = build_toml_header(scmd, e.get_header().clone()); scmd.value_of("content")
debug!("New header set"); .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");
})
}) })
}); });