Move: build_entry_path() from imag-store to libimagstore

This commit is contained in:
Matthias Beyer 2016-03-13 20:49:26 +01:00
parent 8c0c53124b
commit b8b49b3240
6 changed files with 33 additions and 36 deletions

View file

@ -13,10 +13,10 @@ use clap::ArgMatches;
use libimagrt::runtime::Runtime; 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 error::StoreError; use error::StoreError;
use error::StoreErrorKind; use error::StoreErrorKind;
use util::build_entry_path;
use util::build_toml_header; use util::build_toml_header;
type Result<T> = RResult<T, StoreError>; type Result<T> = RResult<T, StoreError>;

View file

@ -1,9 +1,8 @@
use std::path::PathBuf; use std::path::PathBuf;
use libimagstore::storeid::build_entry_path;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use util::build_entry_path;
pub fn delete(rt: &Runtime) { pub fn delete(rt: &Runtime) {
use std::process::exit; use std::process::exit;

View file

@ -6,10 +6,9 @@ use clap::ArgMatches;
use toml::Value; use toml::Value;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagstore::storeid::build_entry_path;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use util::build_entry_path;
pub fn retrieve(rt: &Runtime) { pub fn retrieve(rt: &Runtime) {
rt.cli() rt.cli()
.subcommand_matches("retrieve") .subcommand_matches("retrieve")

View file

@ -2,8 +2,8 @@ use std::path::PathBuf;
use std::ops::DerefMut; use std::ops::DerefMut;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use util::build_toml_header;
use util::build_entry_path; use util::build_entry_path;
use util::build_toml_header;
pub fn update(rt: &Runtime) { pub fn update(rt: &Runtime) {
rt.cli() rt.cli()

View file

@ -10,36 +10,6 @@ use libimagstore::store::EntryHeader;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagutil::key_value_split::IntoKeyValue; use libimagutil::key_value_split::IntoKeyValue;
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
}
pub fn build_toml_header(matches: &ArgMatches, mut header: EntryHeader) -> EntryHeader { pub fn build_toml_header(matches: &ArgMatches, mut header: EntryHeader) -> EntryHeader {
debug!("Building header from cli spec"); debug!("Building header from cli spec");
if let Some(headerspecs) = matches.values_of("header") { if let Some(headerspecs) = matches.values_of("header") {

View file

@ -16,6 +16,35 @@ impl IntoStoreId for PathBuf {
} }
} }
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
}
#[macro_export] #[macro_export]
macro_rules! module_entry_path_mod { macro_rules! module_entry_path_mod {