Merge pull request #1004 from matthiasbeyer/libimagstore/glob-iterator-fix

Reimplement GlobStoreIdIterator
This commit is contained in:
Matthias Beyer 2017-07-23 11:59:00 +02:00 committed by GitHub
commit fc5bbc3b9d

View file

@ -1037,6 +1037,15 @@ mod glob_store_iter {
use libimagerror::trace::trace_error; 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 { pub struct GlobStoreIdIterator {
store_path: PathBuf, store_path: PathBuf,
paths: Paths, paths: Paths,
@ -1075,17 +1084,31 @@ mod glob_store_iter {
type Item = StoreId; type Item = StoreId;
fn next(&mut self) -> Option<StoreId> { fn next(&mut self) -> Option<StoreId> {
self.paths while let Some(o) = self.paths.next() {
.next() debug!("GlobStoreIdIterator::next() => {:?}", o);
.and_then(|o| { match o.map_err_into(SEK::StoreIdHandlingError) {
debug!("GlobStoreIdIterator::next() => {:?}", o); Ok(path) => {
o.map_err_into(SEK::StoreIdHandlingError) if path.exists() && path.is_file() {
.and_then(|p| StoreId::from_full_path(&self.store_path, p)) return match StoreId::from_full_path(&self.store_path, path) {
.map_err(|e| { Ok(id) => Some(id),
debug!("GlobStoreIdIterator error: {:?}", e); Err(e) => {
trace_error(&e); trace_error(&e);
}).ok() None
}) }
}
/* } else { */
/* continue */
}
}
Err(e) => {
debug!("GlobStoreIdIterator error: {:?}", e);
trace_error(&e);
return None
}
}
}
None
} }
} }