diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-02-01 19:26:41 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-02-09 13:48:14 +0100 |
commit | 8c6fc7ef41d9a41f9dee140482afe9d3fce57851 (patch) | |
tree | 9fa101870039ebdf620c343c5bc37c8e66854242 /imag-store | |
parent | 6a0baf7bc530bffdf1645e044d7b8fcdae6833a5 (diff) |
util: Verify that path contains version, else panic!()
Diffstat (limited to 'imag-store')
-rw-r--r-- | imag-store/src/util.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/imag-store/src/util.rs b/imag-store/src/util.rs index d339dc6f..6ebb3a2d 100644 --- a/imag-store/src/util.rs +++ b/imag-store/src/util.rs @@ -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('/') { |