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,13 +9,22 @@ 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")
.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); debug!("path = {:?}", path);
rt.store() rt.store()
// "id" must be present, enforced via clap spec // "id" must be present, enforced via clap spec
.retrieve(path) .retrieve(path)
@ -23,7 +33,7 @@ pub fn retrieve(rt: &Runtime) {
debug!("No entry."); debug!("No entry.");
debug!("{}", e); debug!("{}", e);
}) })
})
}); });
} }

View file

@ -1,16 +1,28 @@
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| {
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() rt.store()
.retrieve(scmd.value_of("id").map(|id| build_entry_path(rt, id)).unwrap()) .retrieve(path)
.map(|mut locked_e| { .map(|mut locked_e| {
let mut e = locked_e.deref_mut(); let mut e = locked_e.deref_mut();
@ -23,6 +35,7 @@ pub fn update(rt: &Runtime) {
*e.get_header_mut() = build_toml_header(scmd, e.get_header().clone()); *e.get_header_mut() = build_toml_header(scmd, e.get_header().clone());
debug!("New header set"); debug!("New header set");
}) })
})
}); });
} }