Merge branch 'hash-type-in-filename'

This commit is contained in:
Matthias Beyer 2015-12-03 17:37:34 +01:00
commit d4cb51486b
2 changed files with 51 additions and 11 deletions

View file

@ -224,12 +224,20 @@ impl StorageBackend {
}
fn build_filepath_with_id(&self, owner: &Module, id: FileID) -> String {
let idstr : String = id.clone().into();
let idtype : FileIDType = id.into();
let typestr : String = idtype.into();
debug!("Building filepath with id");
debug!(" basepath: '{}'", self.basepath);
debug!(" storepath: '{}'", self.storepath);
debug!(" id : '{}'", id);
let idstr : String = id.into();
self.prefix_of_files_for_module(owner) + "-" + &idstr[..] + ".imag"
debug!(" id: '{}'", idstr);
debug!(" type: '{}'", typestr);
self.prefix_of_files_for_module(owner) +
"-" + &typestr[..] +
"-" + &idstr[..] +
".imag"
}
fn prefix_of_files_for_module(&self, m: &Module) -> String {

View file

@ -18,6 +18,38 @@ pub enum FileIDType {
UUID,
}
impl Into<String> for FileIDType {
fn into(self) -> String {
let s = match self {
FileIDType::UUID => "UUID",
FileIDType::NONE => "",
};
String::from(s)
}
}
impl<'a> From<&'a str> for FileIDType {
fn from(s: &'a str) -> FileIDType {
match s {
"UUID" => FileIDType::UUID,
_ => FileIDType::NONE,
}
}
}
impl From<String> for FileIDType {
fn from(s: String) -> FileIDType {
FileIDType::from(&s[..])
}
}
#[derive(Clone)]
pub struct FileID {
id: Option<String>,
@ -77,6 +109,13 @@ impl Into<String> for FileID {
}
impl Into<FileIDType> for FileID {
fn into(self) -> FileIDType {
self.id_type.clone()
}
}
impl From<String> for FileID {
fn from(s: String) -> FileID {
@ -112,7 +151,7 @@ impl<'a> From<&'a String> for FileID {
debug!(" Hash Name: {:?}", hashname);
debug!(" Hash: {:?}", hash);
let idtype = select_id_type_from_str(hashname);
let idtype = FileIDType::from(hashname);
match idtype {
FileIDType::NONE => hash = "INVALID",
_ => {},
@ -192,13 +231,6 @@ impl<'a> Display for FileIDError {
}
fn select_id_type_from_str(s: &str) -> FileIDType {
match s {
"UUID" => FileIDType::UUID,
_ => FileIDType::NONE,
}
}
pub type FileIDResult = Result<FileID, FileIDError>;
#[cfg(test)]