Merge pull request #1102 from matthiasbeyer/libimagentrylink/consistency-check-fix

libimagentrylink: consistency check fix
This commit is contained in:
Matthias Beyer 2017-09-21 19:30:25 +02:00 committed by GitHub
commit 42599d4132

View file

@ -621,10 +621,10 @@ pub mod store_check {
use error::Result as LResult;
use internal::InternalLinker;
use libimagstore::store::StoreObject;
use libimagstore::storeid::StoreId;
use libimagerror::iter::TraceIterator;
use libimagstore::iter::get::StoreIdGetIteratorExtension;
use libimagutil::iter::FoldResult;
use libimagutil::debug_result::DebugResult;
// Helper data structure to collect incoming and outgoing links for each StoreId
#[derive(Debug, Default)]
@ -641,55 +641,39 @@ pub mod store_check {
///
/// The lambda returns an error if something fails
let aggregate_link_network = |store: &Store| -> Result<HashMap<StoreId, Linking>> {
store
.walk("") // this is a hack... I know...
.filter_map(|obj: StoreObject| match obj {
StoreObject::Id(id) => Some(id),
_ => None
}) // Only ids are interesting
.fold(Ok(HashMap::new()), |acc, sid| {
acc.and_then(|mut state| {
debug!("Checking entry: '{}'", sid);
let iter = store
.entries()
.chain_err(|| LEK::StoreReadError)?
.into_get_iter(store);
match try!(self.get(sid).chain_err(|| LEK::StoreError)) {
Some(fle) => {
debug!("Found FileLockEntry");
let mut map = HashMap::new();
for element in iter {
debug!("Checking element = {:?}", element);
let entry = match element {
Ok(Some(e)) => e,
Ok(None) => return Err(LE::from_kind(LEK::StoreIdError)),
Err(e) => return Err(e).chain_err(|| LE::from_kind(LEK::StoreReadError)),
};
let fle_loc = fle.get_location();
debug!("Checking entry = {:?}", entry.get_location());
let internal_links = fle
let internal_links = entry
.get_internal_links()
.chain_err(|| LEK::StoreError)?
.into_getter(self) // get the FLEs from the Store
.trace_unwrap(); // trace all Err(e)s and get the Ok(fle)s
.into_getter(store); // get the FLEs from the Store
let mut linking = Linking::default();
for internal_link in internal_links {
let il_loc = internal_link.get_location();
debug!("internal link = {:?}", internal_link);
state
.entry(il_loc.clone())
.or_insert(Linking::default())
.incoming
.push(fle_loc.clone());
// Make sure an empty linking object is present for the
// current StoreId object
state
.entry(fle_loc.clone())
.or_insert(Linking::default())
.outgoing
.push(il_loc.clone());
linking.outgoing.push(try!(internal_link).get_location().clone());
linking.incoming.push(entry.get_location().clone());
}
Ok(state)
},
None => {
debug!("No entry");
Ok(state)
map.insert(entry.get_location().clone(), linking);
}
}
})
})
Ok(map)
};
/// Helper to check whethre all StoreIds in the network actually exists
@ -768,6 +752,14 @@ pub mod store_check {
};
aggregate_link_network(&self)
.map_dbg_str("Aggregated")
.map_dbg(|nw| {
let mut s = String::new();
for (k, v) in nw {
s.push_str(&format!("{}\n in: {:?}\n out: {:?}", k, v.incoming, v.outgoing));
}
s
})
.and_then(|nw| {
all_collected_storeids_exist(&nw)
.map(|_| nw)