Move: build_entry_path() from imag-store to libimagstore
This commit is contained in:
parent
8c0c53124b
commit
b8b49b3240
6 changed files with 33 additions and 36 deletions
|
@ -13,10 +13,10 @@ use clap::ArgMatches;
|
|||
use libimagrt::runtime::Runtime;
|
||||
use libimagstore::store::Entry;
|
||||
use libimagstore::store::EntryHeader;
|
||||
use libimagstore::storeid::build_entry_path;
|
||||
|
||||
use error::StoreError;
|
||||
use error::StoreErrorKind;
|
||||
use util::build_entry_path;
|
||||
use util::build_toml_header;
|
||||
|
||||
type Result<T> = RResult<T, StoreError>;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use libimagstore::storeid::build_entry_path;
|
||||
use libimagrt::runtime::Runtime;
|
||||
|
||||
use util::build_entry_path;
|
||||
|
||||
pub fn delete(rt: &Runtime) {
|
||||
use std::process::exit;
|
||||
|
||||
|
|
|
@ -6,10 +6,9 @@ use clap::ArgMatches;
|
|||
use toml::Value;
|
||||
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagstore::storeid::build_entry_path;
|
||||
use libimagrt::runtime::Runtime;
|
||||
|
||||
use util::build_entry_path;
|
||||
|
||||
pub fn retrieve(rt: &Runtime) {
|
||||
rt.cli()
|
||||
.subcommand_matches("retrieve")
|
||||
|
|
|
@ -2,8 +2,8 @@ use std::path::PathBuf;
|
|||
use std::ops::DerefMut;
|
||||
|
||||
use libimagrt::runtime::Runtime;
|
||||
use util::build_toml_header;
|
||||
use util::build_entry_path;
|
||||
use util::build_toml_header;
|
||||
|
||||
pub fn update(rt: &Runtime) {
|
||||
rt.cli()
|
||||
|
|
|
@ -10,36 +10,6 @@ use libimagstore::store::EntryHeader;
|
|||
use libimagrt::runtime::Runtime;
|
||||
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 {
|
||||
debug!("Building header from cli spec");
|
||||
if let Some(headerspecs) = matches.values_of("header") {
|
||||
|
|
|
@ -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_rules! module_entry_path_mod {
|
||||
|
|
Loading…
Reference in a new issue