diff --git a/src/api2/admin/datastore/backup/environment.rs b/src/api2/admin/datastore/backup/environment.rs index cffa555b..af580b69 100644 --- a/src/api2/admin/datastore/backup/environment.rs +++ b/src/api2/admin/datastore/backup/environment.rs @@ -231,9 +231,18 @@ impl BackupEnvironment { }; if data.chunk_count != chunk_count { - bail!("fixed writer '{}' close failed - unexpected chunk count ({} != {})", data.name, data.chunk_count, chunk_count); + bail!("fixed writer '{}' close failed - received wrong number of chunk ({} != {})", data.name, data.chunk_count, chunk_count); } + let expected_count = data.index.index_length(); + + if chunk_count != (expected_count as u64) { + bail!("fixed writer '{}' close failed - unexpected chunk count ({} != {})", data.name, expected_count, chunk_count); + } + + if size != (data.size as u64) { + bail!("fixed writer '{}' close failed - unexpected file size ({} != {})", data.name, data.size, size); + } data.index.close()?; diff --git a/src/backup/fixed_index.rs b/src/backup/fixed_index.rs index 8f664d7f..be599a34 100644 --- a/src/backup/fixed_index.rs +++ b/src/backup/fixed_index.rs @@ -278,6 +278,10 @@ impl FixedIndexWriter { }) } + pub fn index_length(&self) -> usize { + self.index_length + } + fn unmap(&mut self) -> Result<(), Error> { if self.index == std::ptr::null_mut() { return Ok(()); } @@ -354,7 +358,6 @@ impl FixedIndexWriter { } pub fn add_digest(&mut self, index: usize, digest: &[u8; 32]) -> Result<(), Error> { - if index >= self.index_length { bail!("add digest failed - index out of range ({} >= {})", index, self.index_length); }