src/api2/backup/upload_chunk.rs: compute crc on upload
This commit is contained in:
parent
ba01828d38
commit
6f083b7a92
|
@ -53,10 +53,13 @@ impl Future for UploadChunk {
|
|||
bail!("uploaded chunk has unexpected size.");
|
||||
}
|
||||
|
||||
let chunk = DataChunk::from_raw(raw_data, self.digest)?;
|
||||
let mut chunk = DataChunk::from_raw(raw_data, self.digest)?;
|
||||
|
||||
chunk.verify_unencrypted(self.size as usize)?;
|
||||
|
||||
// always comput CRC at server side
|
||||
chunk.set_crc(chunk.compute_crc());
|
||||
|
||||
let (is_duplicate, compressed_size) = self.store.insert_chunk(&chunk)?;
|
||||
|
||||
return Ok(Async::Ready((self.digest, self.size, compressed_size as u32, is_duplicate)))
|
||||
|
|
|
@ -54,7 +54,7 @@ impl DataChunk {
|
|||
}
|
||||
|
||||
/// compute the CRC32 checksum
|
||||
pub fn compute_crc(&mut self) -> u32 {
|
||||
pub fn compute_crc(&self) -> u32 {
|
||||
let mut hasher = crc32fast::Hasher::new();
|
||||
let start = std::mem::size_of::<DataChunkHeader>(); // start after HEAD
|
||||
hasher.update(&self.raw_data[start..]);
|
||||
|
|
Loading…
Reference in New Issue