src/backup/fixed_index.rs: use correct size
We need to consider that the last chunk may have smaller size.
This commit is contained in:
parent
9cc88a7c00
commit
b46c3fad03
|
@ -603,9 +603,14 @@ fn fixed_chunk_index(
|
||||||
env.log(format!("download last backup index for archive '{}'", archive_name));
|
env.log(format!("download last backup index for archive '{}'", archive_name));
|
||||||
|
|
||||||
let count = index.index_count();
|
let count = index.index_count();
|
||||||
|
let image_size = index.index_bytes();
|
||||||
for pos in 0..count {
|
for pos in 0..count {
|
||||||
let digest = index.index_digest(pos).unwrap();
|
let digest = index.index_digest(pos).unwrap();
|
||||||
let size = index.chunk_size as u32;
|
// Note: last chunk can be smaller
|
||||||
|
let start = (pos*index.chunk_size) as u64;
|
||||||
|
let mut end = start + index.chunk_size as u64;
|
||||||
|
if end > image_size { end = image_size; }
|
||||||
|
let size = (end - start) as u32;
|
||||||
env.register_chunk(*digest, size)?;
|
env.register_chunk(*digest, size)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub struct FixedIndexHeader {
|
||||||
pub struct FixedIndexReader {
|
pub struct FixedIndexReader {
|
||||||
_file: File,
|
_file: File,
|
||||||
pub chunk_size: usize,
|
pub chunk_size: usize,
|
||||||
pub size: usize,
|
pub size: u64,
|
||||||
index_length: usize,
|
index_length: usize,
|
||||||
index: *mut u8,
|
index: *mut u8,
|
||||||
pub uuid: [u8; 16],
|
pub uuid: [u8; 16],
|
||||||
|
@ -82,11 +82,11 @@ impl FixedIndexReader {
|
||||||
bail!("got unknown magic number");
|
bail!("got unknown magic number");
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = u64::from_le(header.size) as usize;
|
let size = u64::from_le(header.size);
|
||||||
let ctime = u64::from_le(header.ctime);
|
let ctime = u64::from_le(header.ctime);
|
||||||
let chunk_size = u64::from_le(header.chunk_size) as usize;
|
let chunk_size = u64::from_le(header.chunk_size);
|
||||||
|
|
||||||
let index_length = (size + chunk_size - 1)/chunk_size;
|
let index_length = ((size + chunk_size - 1)/chunk_size) as usize;
|
||||||
let index_size = index_length*32;
|
let index_size = index_length*32;
|
||||||
|
|
||||||
let rawfd = file.as_raw_fd();
|
let rawfd = file.as_raw_fd();
|
||||||
|
@ -111,7 +111,7 @@ impl FixedIndexReader {
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
_file: file,
|
_file: file,
|
||||||
chunk_size,
|
chunk_size: chunk_size as usize,
|
||||||
size,
|
size,
|
||||||
index_length,
|
index_length,
|
||||||
index: data,
|
index: data,
|
||||||
|
@ -158,7 +158,7 @@ impl IndexFile for FixedIndexReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index_bytes(&self) -> u64 {
|
fn index_bytes(&self) -> u64 {
|
||||||
(self.index_length * self.chunk_size) as u64
|
self.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue