From fe0849f8eb2786dcec00fe56444122076aebb849 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 13 Mar 2016 14:32:48 +0100 Subject: [PATCH 1/2] Add implementation for Store::retrieve_for_module() --- libimagstore/src/error.rs | 2 ++ libimagstore/src/store.rs | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index cdb21a41..697143fc 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -33,6 +33,7 @@ pub enum StoreErrorKind { PreHookExecuteError, PostHookExecuteError, StorePathLacksVersion, + GlobError, // maybe more } @@ -62,6 +63,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str { &StoreErrorKind::PreHookExecuteError => "Pre-Hook execution error", &StoreErrorKind::PostHookExecuteError => "Post-Hook execution error", &StoreErrorKind::StorePathLacksVersion => "The supplied store path has no version part", + &StoreErrorKind::GlobError => "glob() error", } } diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 9fa62d73..0122cf06 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -17,6 +17,7 @@ use toml::{Table, Value}; use regex::Regex; use crossbeam; use crossbeam::ScopedJoinHandle; +use glob::glob; use error::{ParserErrorKind, ParserError}; use error::{StoreError, StoreErrorKind}; @@ -307,8 +308,18 @@ impl Store { } /// Iterate over all StoreIds for one module name - pub fn retrieve_for_module(&self, mod_name: &str) -> StoreIdIterator { - unimplemented!(); + pub fn retrieve_for_module(&self, mod_name: &str) -> Result { + let mut path = self.path().clone(); + path.push(mod_name); + + if let Some(path) = path.to_str() { + let path = [ path, "/*" ].join(""); + debug!("glob()ing with '{}'", path); + glob(&path[..]).map(StoreIdIterator::new) + .map_err(|e| StoreError::new(StoreErrorKind::GlobError, Some(Box::new(e)))) + } else { + unimplemented!() + } } /// Return the `FileLockEntry` and write to disk From 041a2a49425b9e1ba5a09cfeed0f4a46f716d8c4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 18 Mar 2016 13:46:16 +0100 Subject: [PATCH 2/2] Add encoding error if typeconversion fails --- libimagstore/src/error.rs | 2 ++ libimagstore/src/store.rs | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index 697143fc..4ad9c5f2 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -34,6 +34,7 @@ pub enum StoreErrorKind { PostHookExecuteError, StorePathLacksVersion, GlobError, + EncodingError, // maybe more } @@ -64,6 +65,7 @@ fn store_error_type_as_str(e: &StoreErrorKind) -> &'static str { &StoreErrorKind::PostHookExecuteError => "Post-Hook execution error", &StoreErrorKind::StorePathLacksVersion => "The supplied store path has no version part", &StoreErrorKind::GlobError => "glob() error", + &StoreErrorKind::EncodingError => "Encoding error", } } diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 0122cf06..201386d5 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -315,10 +315,11 @@ impl Store { if let Some(path) = path.to_str() { let path = [ path, "/*" ].join(""); debug!("glob()ing with '{}'", path); - glob(&path[..]).map(StoreIdIterator::new) + glob(&path[..]) + .map(StoreIdIterator::new) .map_err(|e| StoreError::new(StoreErrorKind::GlobError, Some(Box::new(e)))) } else { - unimplemented!() + Err(StoreError::new(StoreErrorKind::EncodingError, None)) } }