src/backup/fixed_index.rs: improve consistency checks
This commit is contained in:
parent
9b38443314
commit
01af11f340
@ -318,11 +318,9 @@ impl FixedIndexWriter {
|
|||||||
&self.stat
|
&self.stat
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: We want to add data out of order, so do not assume and order here.
|
// Note: We want to add data out of order, so do not assume any order here.
|
||||||
pub fn add_chunk(&mut self, pos: usize, chunk: &[u8]) -> Result<(), Error> {
|
pub fn add_chunk(&mut self, pos: usize, chunk: &[u8]) -> Result<(), Error> {
|
||||||
|
|
||||||
if self.index == std::ptr::null_mut() { bail!("cannot write to closed index file."); }
|
|
||||||
|
|
||||||
let end = pos + chunk.len();
|
let end = pos + chunk.len();
|
||||||
|
|
||||||
if end > self.size {
|
if end > self.size {
|
||||||
@ -335,11 +333,8 @@ impl FixedIndexWriter {
|
|||||||
bail!("got chunk with wrong length ({} != {}", chunk.len(), self.chunk_size);
|
bail!("got chunk with wrong length ({} != {}", chunk.len(), self.chunk_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if pos >= self.size { bail!("add chunk after end ({} >= {})", pos, self.size); }
|
|
||||||
|
|
||||||
if pos & (self.chunk_size-1) != 0 { bail!("add unaligned chunk (pos = {})", pos); }
|
if pos & (self.chunk_size-1) != 0 { bail!("add unaligned chunk (pos = {})", pos); }
|
||||||
|
|
||||||
|
|
||||||
let (is_duplicate, digest, compressed_size) = self.store.insert_chunk(chunk)?;
|
let (is_duplicate, digest, compressed_size) = self.store.insert_chunk(chunk)?;
|
||||||
|
|
||||||
self.stat.chunk_count += 1;
|
self.stat.chunk_count += 1;
|
||||||
@ -358,10 +353,13 @@ impl FixedIndexWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_digest(&mut self, index: usize, digest: &[u8; 32]) -> Result<(), Error> {
|
pub fn add_digest(&mut self, index: usize, digest: &[u8; 32]) -> Result<(), Error> {
|
||||||
|
|
||||||
if index >= self.index_length {
|
if index >= self.index_length {
|
||||||
bail!("add digest failed - index out of range ({} >= {})", index, self.index_length);
|
bail!("add digest failed - index out of range ({} >= {})", index, self.index_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.index == std::ptr::null_mut() { bail!("cannot write to closed index file."); }
|
||||||
|
|
||||||
let index_pos = index*32;
|
let index_pos = index*32;
|
||||||
unsafe {
|
unsafe {
|
||||||
let dst = self.index.add(index_pos);
|
let dst = self.index.add(index_pos);
|
||||||
|
Loading…
Reference in New Issue
Block a user