diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index c4d08326..a3f6955e 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -35,6 +35,8 @@ use hook::accessor::{ MutableHookDataAccessor, use hook::position::HookPosition; use hook::Hook; +use self::glob_store_iter::*; + /// The Result Type returned by any interaction with the store that could fail pub type Result = RResult; @@ -361,7 +363,7 @@ impl Store { let path = [ path, "/*" ].join(""); debug!("glob()ing with '{}'", path); glob(&path[..]) - .map(StoreIdIterator::new) + .map(|paths| StoreIdIterator::new(Box::new(GlobStoreIdIterator::new(paths)))) .map_err(|e| StoreError::new(StoreErrorKind::GlobError, Some(Box::new(e)))) } else { Err(StoreError::new(StoreErrorKind::EncodingError, None)) @@ -1253,6 +1255,53 @@ impl Entry { } +mod glob_store_iter { + use std::fmt::{Debug, Formatter}; + use std::fmt::Error as FmtError; + use glob::Paths; + use storeid::StoreId; + + pub struct GlobStoreIdIterator { + paths: Paths, + } + + impl Debug for GlobStoreIdIterator { + + fn fmt(&self, fmt: &mut Formatter) -> Result<(), FmtError> { + write!(fmt, "GlobStoreIdIterator") + } + + } + + impl GlobStoreIdIterator { + + pub fn new(paths: Paths) -> GlobStoreIdIterator { + GlobStoreIdIterator { + paths: paths, + } + } + + } + + impl Iterator for GlobStoreIdIterator { + type Item = StoreId; + + fn next(&mut self) -> Option { + self.paths.next().and_then(|o| { + match o { + Ok(o) => Some(o), + Err(e) => { + debug!("GlobStoreIdIterator error: {:?}", e); + None + }, + } + }).map(|p| StoreId::from(p)) + } + + } + +} + #[cfg(test)] mod test { diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index d5229e2b..7481b6f8 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -3,7 +3,6 @@ use std::path::Path; use std::borrow::Borrow; use std::ops::Deref; -use glob::Paths; use semver::Version; use std::fmt::{Debug, Formatter}; use std::fmt::Error as FmtError; @@ -156,7 +155,7 @@ macro_rules! module_entry_path_mod { } pub struct StoreIdIterator { - paths: Paths, + iter: Box>, } impl Debug for StoreIdIterator { @@ -169,9 +168,9 @@ impl Debug for StoreIdIterator { impl StoreIdIterator { - pub fn new(paths: Paths) -> StoreIdIterator { + pub fn new(iter: Box>) -> StoreIdIterator { StoreIdIterator { - paths: paths, + iter: iter, } } @@ -181,7 +180,7 @@ impl Iterator for StoreIdIterator { type Item = StoreId; fn next(&mut self) -> Option { - self.paths.next().and_then(|o| o.ok()).map(|p| StoreId::from(p)) + self.iter.next() } }