Add build_entry_path(), Copy of imag-store/src/util/build_entry_path()
This commit is contained in:
parent
966cedb4a7
commit
d8d7dae488
1 changed files with 36 additions and 0 deletions
36
imag-tag/src/util.rs
Normal file
36
imag-tag/src/util.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
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
|
||||
}
|
||||
|
Loading…
Reference in a new issue