Refactor libimagentryannotation to fit new store iterator interface

This commit is contained in:
Matthias Beyer 2018-04-30 17:28:54 +02:00
parent 40688a3c2d
commit 6f81d02445
2 changed files with 17 additions and 13 deletions

View file

@ -92,7 +92,7 @@ impl Annotateable for Entry {
fn annotations<'a>(&self, store: &'a Store) -> Result<AnnotationIter<'a>> { fn annotations<'a>(&self, store: &'a Store) -> Result<AnnotationIter<'a>> {
self.get_internal_links() self.get_internal_links()
.map_err(From::from) .map_err(From::from)
.map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone())))) .map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone()).map(Ok))))
.map(|i| AnnotationIter::new(i, store)) .map(|i| AnnotationIter::new(i, store))
} }

View file

@ -24,6 +24,7 @@ use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreIdIterator; use libimagstore::storeid::StoreIdIterator;
use error::Result; use error::Result;
use error::AnnotationError as AE;
use error::AnnotationErrorKind as AEK; use error::AnnotationErrorKind as AEK;
use error::ResultExt; use error::ResultExt;
@ -43,18 +44,21 @@ impl<'a> Iterator for AnnotationIter<'a> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
loop { loop {
match self.0.next().map(|id| self.1.get(id)) { match self.0.next() {
Some(Ok(Some(entry))) => { None => return None, // iterator consumed
match entry.get_header().read_bool("annotation.is_annotation").chain_err(|| AEK::HeaderReadError) { Some(Err(e)) => return Some(Err(e).map_err(AE::from)),
Ok(None) => continue, // not an annotation Some(Ok(id)) => match self.1.get(id) {
Ok(Some(false)) => continue, Err(e) => return Some(Err(e).chain_err(|| AEK::StoreReadError)),
Ok(Some(true)) => return Some(Ok(entry)), Ok(Some(entry)) => {
Err(e) => return Some(Err(e)), match entry.get_header().read_bool("annotation.is_annotation").chain_err(|| AEK::HeaderReadError) {
} Ok(None) => continue, // not an annotation
}, Ok(Some(false)) => continue,
Some(Ok(None)) => continue, Ok(Some(true)) => return Some(Ok(entry)),
Some(Err(e)) => return Some(Err(e).chain_err(|| AEK::StoreReadError)), Err(e) => return Some(Err(e)),
None => return None, // iterator consumed }
},
Ok(None) => continue,
}
} }
} }
} }