src/backup/archive_index.rs: implement flush()

This commit is contained in:
Dietmar Maurer
2018-12-31 18:01:07 +01:00
parent 0433db1949
commit 94a882e900
3 changed files with 21 additions and 3 deletions

View File

@ -128,6 +128,23 @@ impl <'a> Write for ArchiveIndexWriter<'a> {
fn flush(&mut self) -> std::result::Result<(), std::io::Error> {
Ok(())
use std::io::{Error, ErrorKind};
let chunk_size = self.chunk_buffer.len();
if chunk_size == 0 { return Ok(()); }
// fixme: finalize index, disable further writes
match self.store.insert_chunk(&self.chunk_buffer) {
Ok((is_duplicate, digest)) => {
println!("ADD LAST CHUNK {} {} {} {}", self.last_chunk, chunk_size, is_duplicate, digest_to_hex(&digest));
self.chunk_buffer.truncate(0);
Ok(())
}
Err(err) => {
self.chunk_buffer.truncate(0);
Err(Error::new(ErrorKind::Other, err.to_string()))
}
}
}
}