Only mark chunks as checked when not repaired (re #14)

This commit is contained in:
Dennis Schwerdel 2017-04-17 15:55:27 +02:00
parent bd23aac64c
commit 001a36a1eb
1 changed files with 16 additions and 15 deletions

View File

@ -75,12 +75,14 @@ impl Repository {
res
}
fn check_chunks(&self, checked: &mut Bitmap, chunks: &[Chunk]) -> Result<bool, RepositoryError> {
fn check_chunks(&self, checked: &mut Bitmap, chunks: &[Chunk], mark: bool) -> Result<bool, RepositoryError> {
let mut new = false;
for &(hash, _len) in chunks {
if let Some(pos) = self.index.pos(&hash) {
new |= !checked.get(pos);
if mark {
checked.set(pos);
}
} else {
return Err(IntegrityError::MissingChunk(hash).into())
}
@ -92,13 +94,13 @@ impl Repository {
match inode.data {
None | Some(FileData::Inline(_)) => (),
Some(FileData::ChunkedDirect(ref chunks)) => {
try!(self.check_chunks(checked, chunks));
try!(self.check_chunks(checked, chunks, true));
},
Some(FileData::ChunkedIndirect(ref chunks)) => {
if try!(self.check_chunks(checked, chunks)) {
if try!(self.check_chunks(checked, chunks, true)) {
let chunk_data = try!(self.get_data(&chunks));
let chunks = ChunkList::read_from(&chunk_data);
try!(self.check_chunks(checked, &chunks));
try!(self.check_chunks(checked, &chunks, true));
}
}
}
@ -107,7 +109,7 @@ impl Repository {
fn check_subtree(&mut self, path: PathBuf, chunks: &[Chunk], checked: &mut Bitmap, repair: bool) -> Result<Option<ChunkList>, RepositoryError> {
let mut modified = false;
match self.check_chunks(checked, chunks) {
match self.check_chunks(checked, chunks, false) {
Ok(false) => return Ok(None),
Ok(true) => (),
Err(err) => return Err(IntegrityError::BrokenInode(path, Box::new(err)).into())
@ -152,6 +154,7 @@ impl Repository {
if modified {
Ok(Some(try!(self.put_inode(&inode))))
} else {
try!(self.check_chunks(checked, chunks, true));
Ok(None)
}
}
@ -234,8 +237,7 @@ impl Repository {
*chunks = c;
modified = true;
},
Err(err) => {
if repair {
Err(err) => if repair {
warn!("Problem detected: inode {:?} is corrupt\n\tcaused by: {}", path.join(name), err);
info!("Removing broken inode from backup");
removed.push(name.to_string());
@ -245,7 +247,6 @@ impl Repository {
}
}
}
}
for name in removed {
children.remove(&name);
}