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> { fn flush(&mut self) -> std::result::Result<(), std::io::Error> {
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(()) Ok(())
} }
Err(err) => {
self.chunk_buffer.truncate(0);
Err(Error::new(ErrorKind::Other, err.to_string()))
}
}
}
} }

View File

@ -11,7 +11,6 @@ use proxmox_backup::api::router::*;
//use proxmox_backup::backup::image_index::*; //use proxmox_backup::backup::image_index::*;
//use proxmox_backup::config::datastore; //use proxmox_backup::config::datastore;
use proxmox_backup::catar::encoder::*; use proxmox_backup::catar::encoder::*;
use proxmox_backup::backup::chunker::*;
use proxmox_backup::backup::datastore::*; use proxmox_backup::backup::datastore::*;
use serde_json::{Value}; use serde_json::{Value};
@ -44,7 +43,7 @@ fn backup_dir(
// .truncate(true) // .truncate(true)
// .open("mytest.catar")?; // .open("mytest.catar")?;
let mut index = datastore.create_archive_writer(&target, chunk_size)?; let index = datastore.create_archive_writer(&target, chunk_size)?;
let path = std::path::PathBuf::from(path); let path = std::path::PathBuf::from(path);

View File

@ -55,6 +55,8 @@ impl <W: Write> CaTarEncoder<W> {
// todo: use scandirat?? // todo: use scandirat??
me.encode_dir(dir)?; me.encode_dir(dir)?;
me.writer.flush()?;
Ok(()) Ok(())
} }