Repair bundle map too (re #3)

pull/10/head
Dennis Schwerdel 2017-04-13 07:46:16 +02:00
parent df30f7a8fe
commit aadcea678d
2 changed files with 25 additions and 5 deletions

View File

@ -422,7 +422,7 @@ pub fn run() -> Result<(), ErrorCode> {
},
Arguments::Check{repo_path, backup_name, inode, bundles, index, bundle_data, repair} => {
let mut repo = try!(open_repository(&repo_path));
checked!(repo.check_repository(), "check repository", ErrorCode::CheckRun);
checked!(repo.check_repository(repair), "check repository", ErrorCode::CheckRun);
if bundles {
checked!(repo.check_bundles(bundle_data, repair), "check bundles", ErrorCode::CheckRun);
}

View File

@ -276,19 +276,39 @@ impl Repository {
Ok(())
}
pub fn check_repository(&mut self) -> Result<(), RepositoryError> {
pub fn check_repository(&mut self, repair: bool) -> Result<(), RepositoryError> {
info!("Checking repository integrity...");
let mut rebuild = false;
for (_id, bundle_id) in self.bundle_map.bundles() {
if self.bundles.get_bundle_info(&bundle_id).is_none() {
if repair {
warn!("Problem detected: bundle map contains unknown bundle {}", bundle_id);
rebuild = true;
} else {
return Err(IntegrityError::MissingBundle(bundle_id).into())
}
}
}
if self.bundle_map.len() < self.bundles.len() {
if repair {
warn!("Problem detected: bundle map does not contain all remote bundles");
rebuild = true;
} else {
return Err(IntegrityError::RemoteBundlesNotInMap.into())
}
}
if self.bundle_map.len() > self.bundles.len() {
if repair {
warn!("Problem detected: bundle map contains bundles multiple times");
rebuild = true;
} else {
return Err(IntegrityError::MapContainsDuplicates.into())
}
}
if rebuild {
try!(self.rebuild_bundle_map());
try!(self.rebuild_index());
}
Ok(())
}