diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 4d59c539..40ace0f0 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -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 { diff --git a/src/storage/file_id.rs b/src/storage/file_id.rs index 03e507e0..afc28c0c 100644 --- a/src/storage/file_id.rs +++ b/src/storage/file_id.rs @@ -18,6 +18,38 @@ pub enum FileIDType { UUID, } +impl Into 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 for FileIDType { + + fn from(s: String) -> FileIDType { + FileIDType::from(&s[..]) + } + +} + #[derive(Clone)] pub struct FileID { id: Option, @@ -77,6 +109,13 @@ impl Into for FileID { } +impl Into for FileID { + + fn into(self) -> FileIDType { + self.id_type.clone() + } +} + impl From 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; #[cfg(test)]