imag-tag: Fix use of build_entry_path()

This commit is contained in:
Matthias Beyer 2016-03-18 14:38:16 +01:00
parent df740ac63a
commit affa850bc0
2 changed files with 20 additions and 40 deletions

View file

@ -13,12 +13,11 @@ use std::process::exit;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagtag::tagable::Tagable; use libimagtag::tagable::Tagable;
use libimagstore::storeid::build_entry_path;
mod ui; mod ui;
mod util;
use ui::build_ui; use ui::build_ui;
use util::build_entry_path;
use libimagutil::trace::trace_error; use libimagutil::trace::trace_error;
@ -68,8 +67,17 @@ fn main() {
} }
fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Option<&str>) { fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Option<&str>) {
let path = build_entry_path(rt, id); let path = {
match build_entry_path(rt.store(), id) {
Err(e) => {
trace_error(&e);
exit(1);
},
Ok(s) => s,
}
};
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)
@ -110,7 +118,15 @@ fn alter(rt: &Runtime, id: &str, add: Option<&str>, rem: Option<&str>, set: Opti
} }
fn list(id: &str, rt: &Runtime) { fn list(id: &str, rt: &Runtime) {
let path = build_entry_path(rt, id); let path = {
match build_entry_path(rt.store(), id) {
Err(e) => {
trace_error(&e);
exit(1);
},
Ok(s) => s,
}
};
debug!("path = {:?}", path); debug!("path = {:?}", path);
let entry = rt.store().retrieve(path.clone()); let entry = rt.store().retrieve(path.clone());

View file

@ -1,36 +0,0 @@
use std::path::PathBuf;
use semver::Version;
use libimagrt::runtime::Runtime;
pub fn build_entry_path(rt: &Runtime, path_elem: &str) -> PathBuf {
debug!("Checking path element for version");
{
let contains_version = {
path_elem.split("~")
.last()
.map(|version| Version::parse(version).is_ok())
.unwrap_or(false)
};
if !contains_version {
debug!("Version cannot be parsed inside {:?}", path_elem);
warn!("Path does not contain version. Will panic now!");
panic!("No version in path");
}
}
debug!("Version checking succeeded");
debug!("Building path from {:?}", path_elem);
let mut path = rt.store().path().clone();
if path_elem.chars().next() == Some('/') {
path.push(&path_elem[1..path_elem.len()]);
} else {
path.push(path_elem);
}
path
}