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