From 9aced858acbf57631fa1b61e8a6795ac7cd8d5f2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 23 Nov 2015 18:42:55 +0100 Subject: [PATCH] Outsource file id parsing --- src/storage/backend.rs | 9 +++------ src/storage/file.rs | 9 ++------- src/storage/file_id.rs | 16 ++++++++++++++++ src/storage/mod.rs | 1 + 4 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 src/storage/file_id.rs diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 72ed0f62..372edd54 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -9,7 +9,8 @@ use std::vec::Vec; use glob::glob; use glob::Paths; -use storage::file::{File, FileID}; +use storage::file::File; +use storage::file_id::*; use module::Module; type BackendOperationResult = Result<(), StorageBackendError>; @@ -35,7 +36,7 @@ impl<'a> StorageBackend<'a> { let mut v = vec![]; for entry in globlist { if let Ok(path) = entry { - v.push(file_id_from_path(path.as_path())); + v.push(from_pathbuf(&path)); } else { // Entry is not a path } @@ -66,10 +67,6 @@ impl<'a> StorageBackend<'a> { } -fn file_id_from_path(p: &Path) -> String { - String::from("") -} - #[derive(Debug)] pub struct StorageBackendError { pub action: String, // The file system action in words diff --git a/src/storage/file.rs b/src/storage/file.rs index 74413f4a..65293ea7 100644 --- a/src/storage/file.rs +++ b/src/storage/file.rs @@ -3,6 +3,7 @@ use std::fmt::{Debug, Display, Formatter}; use std::fmt; use super::parser::{FileHeaderParser, Parser, ParserError}; +use storage::file_id::*; #[derive(Debug)] pub enum FileHeaderSpec { @@ -162,8 +163,6 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData) None } -pub type FileID = String; - pub struct File { header : FileHeaderData, data : String, @@ -180,7 +179,7 @@ impl<'a> File { Ok(File { header: h, data: d, - id: File::get_id_from_path(path), + id: from_path_string(path), })) } @@ -188,10 +187,6 @@ impl<'a> File { self.id.clone() } - fn get_id_from_path(p: &String) -> FileID { - String::from("") - } - fn read_file(p: &String) -> Result { Ok(String::from("")) } diff --git a/src/storage/file_id.rs b/src/storage/file_id.rs new file mode 100644 index 00000000..dfc320a4 --- /dev/null +++ b/src/storage/file_id.rs @@ -0,0 +1,16 @@ +use std::path::{Path, PathBuf}; + +pub type FileID = String; + +pub fn from_path_string(s: &String) -> FileID { + String::from("") +} + +pub fn from_path(p: &Path) -> FileID { + String::from("") +} + +pub fn from_pathbuf(p: &PathBuf) -> FileID { + from_path(p.as_path()) +} + diff --git a/src/storage/mod.rs b/src/storage/mod.rs index a431b2c9..861d813a 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -5,6 +5,7 @@ pub use std::error::Error; pub use runtime::Runtime; pub mod file; +pub mod file_id; pub mod parser; pub mod backend;