diff --git a/lib/core/libimagstore/src/file_abstraction/fs.rs b/lib/core/libimagstore/src/file_abstraction/fs.rs index a41a2239..8ee7ee9d 100644 --- a/lib/core/libimagstore/src/file_abstraction/fs.rs +++ b/lib/core/libimagstore/src/file_abstraction/fs.rs @@ -168,20 +168,15 @@ impl FileAbstraction for FSFileAbstraction { fn pathes_recursively(&self, basepath: PathBuf) -> Result { use walkdir::WalkDir; - let i : Result, SE> = WalkDir::new(basepath) + let i = WalkDir::new(basepath) .min_depth(1) + .max_open(100) .into_iter() .map(|r| { - r.map(|e| PathBuf::from(e.path())) - .chain_err(|| SE::from_kind(SEK::FileError)) - }) - .fold(Ok(vec![]), |acc, e| { - acc.and_then(move |mut a| { - a.push(e?); - Ok(a) - }) + r.map(|e| PathBuf::from(e.path())).chain_err(|| SE::from_kind(SEK::FileError)) }); - Ok(PathIterator::new(Box::new(i?.into_iter()))) + + Ok(PathIterator::new(Box::new(i))) } } diff --git a/lib/core/libimagstore/src/file_abstraction/inmemory.rs b/lib/core/libimagstore/src/file_abstraction/inmemory.rs index efe0c4f4..495286fd 100644 --- a/lib/core/libimagstore/src/file_abstraction/inmemory.rs +++ b/lib/core/libimagstore/src/file_abstraction/inmemory.rs @@ -183,15 +183,15 @@ impl FileAbstraction for InMemoryFileAbstraction { fn pathes_recursively(&self, _basepath: PathBuf) -> Result { debug!("Getting all pathes"); - let keys : Vec = self + let keys : Vec> = self .backend() .lock() .map_err(|_| SE::from_kind(SEK::FileError))? .get_mut() .keys() .map(PathBuf::from) - .collect(); - // we collect here as this happens only in tests and in memory anyways, so no problem + .map(Ok) + .collect(); // we have to collect() because of the lock() above. Ok(PathIterator::new(Box::new(keys.into_iter()))) } diff --git a/lib/core/libimagstore/src/file_abstraction/iter.rs b/lib/core/libimagstore/src/file_abstraction/iter.rs index ca2862b3..c0bd8b5f 100644 --- a/lib/core/libimagstore/src/file_abstraction/iter.rs +++ b/lib/core/libimagstore/src/file_abstraction/iter.rs @@ -19,19 +19,21 @@ use std::path::PathBuf; +use error::Result; + /// A wrapper for an iterator over `PathBuf`s -pub struct PathIterator(Box>); +pub struct PathIterator(Box>>); impl PathIterator { - pub fn new(iter: Box>) -> PathIterator { + pub fn new(iter: Box>>) -> PathIterator { PathIterator(iter) } } impl Iterator for PathIterator { - type Item = PathBuf; + type Item = Result; fn next(&mut self) -> Option { self.0.next()