Some fixes

This commit is contained in:
Dennis Schwerdel 2017-04-10 18:21:26 +02:00 committed by Dennis Schwerdel
parent 8e4282610c
commit 75be97e7c5
4 changed files with 41 additions and 2 deletions

View File

@ -69,7 +69,7 @@ pub fn load_bundles(path: &Path, base: &Path, bundles: &mut HashMap<BundleId, St
}
}
let mut gone = HashSet::new();
for (id, bundle) in bundles.iter_mut() {
for (id, bundle) in bundles.iter() {
if !bundle_paths.contains(&bundle.path) {
gone.insert(id.clone());
} else {
@ -157,7 +157,7 @@ impl BundleDb {
pub fn update_cache(&mut self, new: &[StoredBundle], gone: &[StoredBundle]) -> Result<(), BundleDbError> {
for bundle in new {
if bundle.info.mode == BundleMode::Meta {
info!("Copying new meta bundle to local cache: {}", bundle.info.id);
debug!("Copying new meta bundle to local cache: {}", bundle.info.id);
try!(self.copy_remote_bundle_to_cache(bundle));
}
}
@ -304,4 +304,10 @@ impl BundleDb {
}
Ok(())
}
#[inline]
pub fn len(&self) -> usize {
self.remote_bundles.len()
}
}

View File

@ -96,4 +96,9 @@ impl BundleMap {
pub fn bundles(&self) -> Vec<(u32, BundleId)> {
self.0.iter().map(|(id, bundle)| (*id, bundle.clone())).collect()
}
#[inline]
pub fn len(&self) -> usize {
self.0.len()
}
}

View File

@ -23,6 +23,12 @@ quick_error!{
description("No such chunk")
display("Bundle {} does not contain the chunk {}", bundle, chunk)
}
RemoteBundlesNotInMap {
description("Remote bundles missing from map")
}
MapContainsDuplicates {
description("Map contains duplicates")
}
InvalidNextBundleId {
description("Invalid next bundle id")
}
@ -158,12 +164,30 @@ impl Repository {
Ok(())
}
fn check_bundle_map(&mut self) -> Result<(), RepositoryError> {
for (_id, bundle_id) in self.bundle_map.bundles() {
if self.bundles.get_bundle_info(&bundle_id).is_none() {
return Err(IntegrityError::MissingBundle(bundle_id).into())
}
}
if self.bundle_map.len() < self.bundles.len() {
return Err(IntegrityError::RemoteBundlesNotInMap.into())
}
if self.bundle_map.len() > self.bundles.len() {
return Err(IntegrityError::MapContainsDuplicates.into())
}
Ok(())
}
pub fn check(&mut self, full: bool) -> Result<(), RepositoryError> {
try!(self.flush());
info!("Checking bundle integrity...");
try!(self.bundles.check(full));
info!("Checking index integrity...");
try!(self.index.check());
info!("Checking bundle map...");
try!(self.check_bundle_map());
info!("Checking index entries...");
try!(self.check_index_chunks());
info!("Checking backup integrity...");
try!(self.check_backups());

View File

@ -216,6 +216,9 @@ impl Repository {
fn add_new_remote_bundle(&mut self, bundle: BundleInfo) -> Result<(), RepositoryError> {
debug!("Adding new bundle to index: {}", bundle.id);
if self.bundle_map.find(&bundle.id).is_some() {
return Ok(())
}
let bundle_id = match bundle.mode {
BundleMode::Data => self.next_data_bundle,
BundleMode::Meta => self.next_meta_bundle
@ -236,6 +239,7 @@ impl Repository {
fn rebuild_bundle_map(&mut self) -> Result<(), RepositoryError> {
info!("Rebuilding bundle map from bundles");
self.bundle_map = BundleMap::create();
for bundle in self.bundles.list_bundles() {
let bundle_id = match bundle.mode {
BundleMode::Data => self.next_data_bundle,