mirror of https://github.com/dswd/zvault
Repair bundle map too (re #3)
This commit is contained in:
parent
df30f7a8fe
commit
aadcea678d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue