util: Verify that path contains version, else panic!()

This commit is contained in:
Matthias Beyer 2016-02-01 19:26:41 +01:00
parent 6a0baf7bc5
commit 8c6fc7ef41

View file

@ -3,6 +3,7 @@ use std::path::PathBuf;
use std::str::Split;
use clap::ArgMatches;
use semver::Version;
use toml::Value;
use libimagstore::store::EntryHeader;
@ -10,7 +11,24 @@ use libimagrt::runtime::Runtime;
use libimagutil::key_value_split::IntoKeyValue;
pub fn build_entry_path(rt: &Runtime, path_elem: &str) -> PathBuf {
debug!("Building path...");
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('/') {