From 9aced858acbf57631fa1b61e8a6795ac7cd8d5f2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 23 Nov 2015 18:42:55 +0100 Subject: [PATCH 1/3] 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; From bff2bf68c65094998e3840fb3a9ee3ca6ba45379 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 23 Nov 2015 18:45:31 +0100 Subject: [PATCH 2/3] We dont need to pass the module here --- src/storage/backend.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/storage/backend.rs b/src/storage/backend.rs index 372edd54..8ea66cde 100644 --- a/src/storage/backend.rs +++ b/src/storage/backend.rs @@ -11,21 +11,18 @@ use glob::Paths; use storage::file::File; use storage::file_id::*; -use module::Module; type BackendOperationResult = Result<(), StorageBackendError>; -pub struct StorageBackend<'a> { +pub struct StorageBackend { basepath: String, - module: &'a Module, } -impl<'a> StorageBackend<'a> { +impl StorageBackend { - fn new(basepath: String, module: &'a Module) -> StorageBackend<'a> { + fn new(basepath: String) -> StorageBackend { StorageBackend { basepath: basepath, - module: module, } } From 25de1c6c2a26b9f61c98bd6b007f7c6287232ef8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 23 Nov 2015 18:46:09 +0100 Subject: [PATCH 3/3] We should use the FileID type in the File --- src/storage/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/file.rs b/src/storage/file.rs index 65293ea7..f1ceedad 100644 --- a/src/storage/file.rs +++ b/src/storage/file.rs @@ -166,7 +166,7 @@ pub fn match_header_spec<'a>(spec: &'a FileHeaderSpec, data: &'a FileHeaderData) pub struct File { header : FileHeaderData, data : String, - id : String + id : FileID, } impl<'a> File {