diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2017-07-23 11:59:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-23 11:59:00 +0200 |
commit | fc5bbc3b9df91f4dd93bfa11ec0b71dddd593d2d (patch) | |
tree | 161d2bed766d5954b76f5429c7c6290a9719462e | |
parent | e4f8d4ec08cd506de10a5c01d6749bb9a993c603 (diff) | |
parent | cbb36875f6044190fa69a17772a44e2396280aa5 (diff) |
Merge pull request #1004 from matthiasbeyer/libimagstore/glob-iterator-fix
Reimplement GlobStoreIdIterator
-rw-r--r-- | libimagstore/src/store.rs | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 58b7c49b..c24e241f 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -1037,6 +1037,15 @@ mod glob_store_iter { use libimagerror::trace::trace_error; + /// An iterator which is constructed from a `glob()` and returns valid `StoreId` objects + /// + /// # Warning + /// + /// On error, this iterator currently traces the error and return None (thus ending the + /// iteration). This is a known issue and will be resolved at some point. + /// + /// TODO: See above. + /// pub struct GlobStoreIdIterator { store_path: PathBuf, paths: Paths, @@ -1075,17 +1084,31 @@ mod glob_store_iter { type Item = StoreId; fn next(&mut self) -> Option<StoreId> { - self.paths - .next() - .and_then(|o| { - debug!("GlobStoreIdIterator::next() => {:?}", o); - o.map_err_into(SEK::StoreIdHandlingError) - .and_then(|p| StoreId::from_full_path(&self.store_path, p)) - .map_err(|e| { - debug!("GlobStoreIdIterator error: {:?}", e); - trace_error(&e); - }).ok() - }) + while let Some(o) = self.paths.next() { + debug!("GlobStoreIdIterator::next() => {:?}", o); + match o.map_err_into(SEK::StoreIdHandlingError) { + Ok(path) => { + if path.exists() && path.is_file() { + return match StoreId::from_full_path(&self.store_path, path) { + Ok(id) => Some(id), + Err(e) => { + trace_error(&e); + None + } + } + /* } else { */ + /* continue */ + } + } + Err(e) => { + debug!("GlobStoreIdIterator error: {:?}", e); + trace_error(&e); + return None + } + } + } + + None } } |