gc: mark_used_chunks: reduce implementation noise

try do reduce some unecessary lines, make match arms more precise so
one can faster see what's actually happening.

Also, avoid
> return Err(format_err!(...))
stuff, just use bail!()

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2020-11-02 20:50:24 +01:00
parent 2f0b92352d
commit 788d82d9b7
1 changed files with 12 additions and 31 deletions

View File

@ -458,54 +458,35 @@ impl DataStore {
) -> Result<(), Error> { ) -> Result<(), Error> {
let image_list = self.list_images()?; let image_list = self.list_images()?;
let image_count = image_list.len(); let image_count = image_list.len();
let mut done = 0; let mut done = 0;
let mut last_percentage: usize = 0; let mut last_percentage: usize = 0;
for path in image_list { for img in image_list {
worker.check_abort()?; worker.check_abort()?;
tools::fail_on_shutdown()?; tools::fail_on_shutdown()?;
let full_path = self.chunk_store.relative_path(&path); let path = self.chunk_store.relative_path(&img);
match std::fs::File::open(&full_path) { match std::fs::File::open(&path) {
Ok(file) => { Ok(file) => {
if let Ok(archive_type) = archive_type(&path) { if let Ok(archive_type) = archive_type(&img) {
if archive_type == ArchiveType::FixedIndex { if archive_type == ArchiveType::FixedIndex {
let index = FixedIndexReader::new(file).map_err(|err| { let index = FixedIndexReader::new(file).map_err(|e| {
format_err!( format_err!("can't read index '{}' - {}", path.to_string_lossy(), e)
"cannot read fixed index {}: {}",
full_path.to_string_lossy(),
err
)
})?; })?;
self.index_mark_used_chunks(index, &path, status, worker)?; self.index_mark_used_chunks(index, &img, status, worker)?;
} else if archive_type == ArchiveType::DynamicIndex { } else if archive_type == ArchiveType::DynamicIndex {
let index = DynamicIndexReader::new(file).map_err(|err| { let index = DynamicIndexReader::new(file).map_err(|e| {
format_err!( format_err!("can't read index '{}' - {}", path.to_string_lossy(), e)
"cannot read dynamic index {}: {}",
full_path.to_string_lossy(),
err
)
})?; })?;
self.index_mark_used_chunks(index, &path, status, worker)?; self.index_mark_used_chunks(index, &img, status, worker)?;
} }
} }
} }
Err(err) => { Err(err) if err.kind() == io::ErrorKind::NotFound => (), // ignore vanished files
if err.kind() == std::io::ErrorKind::NotFound { Err(err) => bail!("can't open index {} - {}", path.to_string_lossy(), err),
// simply ignore vanished files
} else {
return Err(format_err!(
"cannot open index {}: {}",
full_path.to_string_lossy(),
err
));
}
}
} }
done += 1; done += 1;