src/backup/archive_index.rs: implement flush()
This commit is contained in:
		@ -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()))
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,6 @@ use proxmox_backup::api::router::*;
 | 
			
		||||
//use proxmox_backup::backup::image_index::*;
 | 
			
		||||
//use proxmox_backup::config::datastore;
 | 
			
		||||
use proxmox_backup::catar::encoder::*;
 | 
			
		||||
use proxmox_backup::backup::chunker::*;
 | 
			
		||||
use proxmox_backup::backup::datastore::*;
 | 
			
		||||
use serde_json::{Value};
 | 
			
		||||
 | 
			
		||||
@ -44,7 +43,7 @@ fn backup_dir(
 | 
			
		||||
    //    .truncate(true)
 | 
			
		||||
    //    .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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -55,6 +55,8 @@ impl <W: Write> CaTarEncoder<W> {
 | 
			
		||||
        // todo: use scandirat??
 | 
			
		||||
        me.encode_dir(dir)?;
 | 
			
		||||
 | 
			
		||||
        me.writer.flush()?;
 | 
			
		||||
 | 
			
		||||
        Ok(())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user