Rewrite build_entry_path() so it does not panic!() anymore
This commit is contained in:
parent
b8b49b3240
commit
80945fcd16
2 changed files with 14 additions and 16 deletions
|
@ -32,6 +32,7 @@ pub enum StoreErrorKind {
|
||||||
HookExecutionError,
|
HookExecutionError,
|
||||||
PreHookExecuteError,
|
PreHookExecuteError,
|
||||||
PostHookExecuteError,
|
PostHookExecuteError,
|
||||||
|
StorePathLacksVersion,
|
||||||
// maybe more
|
// maybe more
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +61,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str {
|
||||||
&StoreErrorKind::HookExecutionError => "Hook execution error",
|
&StoreErrorKind::HookExecutionError => "Hook execution error",
|
||||||
&StoreErrorKind::PreHookExecuteError => "Pre-Hook execution error",
|
&StoreErrorKind::PreHookExecuteError => "Pre-Hook execution error",
|
||||||
&StoreErrorKind::PostHookExecuteError => "Post-Hook execution error",
|
&StoreErrorKind::PostHookExecuteError => "Post-Hook execution error",
|
||||||
|
&StoreErrorKind::StorePathLacksVersion => "The supplied store path has no version part",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use glob::Paths;
|
use glob::Paths;
|
||||||
|
use semver::Version;
|
||||||
|
|
||||||
|
use error::{StoreError, StoreErrorKind};
|
||||||
|
use store::Result;
|
||||||
|
use store::Store;
|
||||||
|
|
||||||
/// The Index into the Store
|
/// The Index into the Store
|
||||||
pub type StoreId = PathBuf;
|
pub type StoreId = PathBuf;
|
||||||
|
@ -16,26 +21,17 @@ impl IntoStoreId for PathBuf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_entry_path(rt: &Runtime, path_elem: &str) -> PathBuf {
|
pub fn build_entry_path(store: &Store, path_elem: &str) -> Result<PathBuf> {
|
||||||
debug!("Checking path element for version");
|
debug!("Checking path element for version");
|
||||||
{
|
if path_elem.split("~").last().map(|v| Version::parse(v).is_err()).unwrap_or(false) {
|
||||||
let contains_version = {
|
debug!("Version cannot be parsed from {:?}", path_elem);
|
||||||
path_elem.split("~")
|
debug!("Path does not contain version!");
|
||||||
.last()
|
return Err(StoreError::new(StoreErrorKind::StorePathLacksVersion, None));
|
||||||
.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!("Version checking succeeded");
|
||||||
|
|
||||||
debug!("Building path from {:?}", path_elem);
|
debug!("Building path from {:?}", path_elem);
|
||||||
let mut path = rt.store().path().clone();
|
let mut path = store.path().clone();
|
||||||
|
|
||||||
if path_elem.chars().next() == Some('/') {
|
if path_elem.chars().next() == Some('/') {
|
||||||
path.push(&path_elem[1..path_elem.len()]);
|
path.push(&path_elem[1..path_elem.len()]);
|
||||||
|
@ -43,7 +39,7 @@ pub fn build_entry_path(rt: &Runtime, path_elem: &str) -> PathBuf {
|
||||||
path.push(path_elem);
|
path.push(path_elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
path
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
Loading…
Reference in a new issue