From 07cac74ccef4d8da8532bb01c4e5d91ba8ecc1c6 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Tue, 7 Mar 2023 09:16:31 +0100 Subject: [PATCH] check --read-data: Show progress in bytes --- src/commands/check.rs | 26 ++++++++++++++++++++++---- src/index/binarysorted.rs | 4 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/commands/check.rs b/src/commands/check.rs index f463260..44622e3 100644 --- a/src/commands/check.rs +++ b/src/commands/check.rs @@ -73,12 +73,24 @@ pub(super) fn execute(repo: OpenRepository, opts: Opts) -> Result<()> { } } + let total_pack_size: u64 = index_collector + .data_packs() + .iter() + .map(|(_, size)| u64::from(*size)) + .sum::() + + index_collector + .tree_packs() + .iter() + .map(|(_, size)| u64::from(*size)) + .sum::(); + let index_be = IndexBackend::new_from_index(be, index_collector.into_index()); check_snapshots(&index_be)?; if opts.read_data { - let p = progress_counter("reading pack data..."); + let p = progress_bytes("reading pack data..."); + p.set_length(total_pack_size); index_be .into_index() @@ -87,11 +99,10 @@ pub(super) fn execute(repo: OpenRepository, opts: Opts) -> Result<()> { .for_each_with((be.clone(), p.clone()), |(be, p), pack| { let id = pack.id; let data = be.read_full(FileType::Pack, &id).unwrap(); - match check_pack(be, pack, data) { + match check_pack(be, pack, data, p) { Ok(()) => {} Err(err) => error!("Error reading pack {id} : {err}",), } - p.inc(1); }); p.finish(); } @@ -316,7 +327,12 @@ fn check_snapshots(index: &impl IndexedBackend) -> Result<()> { Ok(()) } -fn check_pack(be: &impl DecryptReadBackend, index_pack: IndexPack, mut data: Bytes) -> Result<()> { +fn check_pack( + be: &impl DecryptReadBackend, + index_pack: IndexPack, + mut data: Bytes, + p: &mut ProgressBar, +) -> Result<()> { let id = index_pack.id; let size = index_pack.pack_size(); if data.len() != size as usize { @@ -353,6 +369,7 @@ fn check_pack(be: &impl DecryptReadBackend, index_pack: IndexPack, mut data: Byt debug!("index: {:?}", blobs); return Ok(()); } + p.inc(u64::from(header_len) + 4); // check blobs for blob in blobs { @@ -373,6 +390,7 @@ fn check_pack(be: &impl DecryptReadBackend, index_pack: IndexPack, mut data: Byt error!("pack {id}, blob {blob_id}: Hash mismatch. Computed hash: {comp_id}"); return Ok(()); } + p.inc(blob.length.into()); } Ok(()) diff --git a/src/index/binarysorted.rs b/src/index/binarysorted.rs index 0404d7c..cda29a4 100644 --- a/src/index/binarysorted.rs +++ b/src/index/binarysorted.rs @@ -78,6 +78,10 @@ impl IndexCollector { &self.0[BlobType::Tree].packs } + pub fn data_packs(&self) -> &Vec<(Id, u32)> { + &self.0[BlobType::Data].packs + } + // Turns Collector into an index by sorting the entries by ID. pub fn into_index(self) -> Index { Index(self.0.map(|_, mut tc| {