partially revert commit 1f82f9b7b5

do it backwards compatible. Also, code was wrong because FixedIndexWriter
still computed old style csums...
This commit is contained in:
Dietmar Maurer 2020-06-29 12:44:45 +02:00
parent 4ff2c9b832
commit 2e079b8bf2
3 changed files with 27 additions and 13 deletions

View File

@ -189,6 +189,19 @@ impl IndexFile for DynamicIndexReader {
} }
} }
fn compute_csum(&self) -> ([u8; 32], u64) {
let mut csum = openssl::sha::Sha256::new();
let mut chunk_end = 0;
for pos in 0..self.index_count() {
let info = self.chunk_info(pos).unwrap();
chunk_end = info.range.end;
csum.update(&chunk_end.to_le_bytes());
csum.update(&info.digest);
}
let csum = csum.finish();
(csum, chunk_end)
}
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
fn chunk_info(&self, pos: usize) -> Option<ChunkReadInfo> { fn chunk_info(&self, pos: usize) -> Option<ChunkReadInfo> {
if pos >= self.index.len() { if pos >= self.index.len() {

View File

@ -206,6 +206,19 @@ impl IndexFile for FixedIndexReader {
digest: *digest, digest: *digest,
}) })
} }
fn compute_csum(&self) -> ([u8; 32], u64) {
let mut csum = openssl::sha::Sha256::new();
let mut chunk_end = 0;
for pos in 0..self.index_count() {
let info = self.chunk_info(pos).unwrap();
chunk_end = info.range.end;
csum.update(&info.digest);
}
let csum = csum.finish();
(csum, chunk_end)
}
} }
pub struct FixedIndexWriter { pub struct FixedIndexWriter {

View File

@ -23,19 +23,7 @@ pub trait IndexFile {
fn chunk_info(&self, pos: usize) -> Option<ChunkReadInfo>; fn chunk_info(&self, pos: usize) -> Option<ChunkReadInfo>;
/// Compute index checksum and size /// Compute index checksum and size
fn compute_csum(&self) -> ([u8; 32], u64) { fn compute_csum(&self) -> ([u8; 32], u64);
let mut csum = openssl::sha::Sha256::new();
let mut chunk_end = 0;
for pos in 0..self.index_count() {
let info = self.chunk_info(pos).unwrap();
chunk_end = info.range.end;
csum.update(&chunk_end.to_le_bytes());
csum.update(&info.digest);
}
let csum = csum.finish();
(csum, chunk_end)
}
/// Returns most often used chunks /// Returns most often used chunks
fn find_most_used_chunks(&self, max: usize) -> HashMap<[u8; 32], usize> { fn find_most_used_chunks(&self, max: usize) -> HashMap<[u8; 32], usize> {