Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-06-12 10:59:34 +02:00
parent 4482f3fe11
commit 1498659b4e
1 changed files with 14 additions and 13 deletions

View File

@ -1,17 +1,18 @@
use anyhow::{Error};
use std::sync::Arc; use std::sync::Arc;
use super::datastore::*; use anyhow::Error;
use super::crypt_config::*;
use super::data_blob::*; use super::crypt_config::CryptConfig;
use super::data_blob::DataBlob;
use super::datastore::DataStore;
/// The ReadChunk trait allows reading backup data chunks (local or remote) /// The ReadChunk trait allows reading backup data chunks (local or remote)
pub trait ReadChunk { pub trait ReadChunk {
/// Returns the encoded chunk data /// Returns the encoded chunk data
fn read_raw_chunk(&mut self, digest:&[u8; 32]) -> Result<DataBlob, Error>; fn read_raw_chunk(&mut self, digest: &[u8; 32]) -> Result<DataBlob, Error>;
/// Returns the decoded chunk data /// Returns the decoded chunk data
fn read_chunk(&mut self, digest:&[u8; 32]) -> Result<Vec<u8>, Error>; fn read_chunk(&mut self, digest: &[u8; 32]) -> Result<Vec<u8>, Error>;
} }
pub struct LocalChunkReader { pub struct LocalChunkReader {
@ -20,16 +21,16 @@ pub struct LocalChunkReader {
} }
impl LocalChunkReader { impl LocalChunkReader {
pub fn new(store: Arc<DataStore>, crypt_config: Option<Arc<CryptConfig>>) -> Self { pub fn new(store: Arc<DataStore>, crypt_config: Option<Arc<CryptConfig>>) -> Self {
Self { store, crypt_config } Self {
store,
crypt_config,
}
} }
} }
impl ReadChunk for LocalChunkReader { impl ReadChunk for LocalChunkReader {
fn read_raw_chunk(&mut self, digest: &[u8; 32]) -> Result<DataBlob, Error> {
fn read_raw_chunk(&mut self, digest:&[u8; 32]) -> Result<DataBlob, Error> {
let digest_str = proxmox::tools::digest_to_hex(digest); let digest_str = proxmox::tools::digest_to_hex(digest);
println!("READ CHUNK {}", digest_str); println!("READ CHUNK {}", digest_str);
@ -41,7 +42,7 @@ impl ReadChunk for LocalChunkReader {
Ok(chunk) Ok(chunk)
} }
fn read_chunk(&mut self, digest:&[u8; 32]) -> Result<Vec<u8>, Error> { fn read_chunk(&mut self, digest: &[u8; 32]) -> Result<Vec<u8>, Error> {
let chunk = self.read_raw_chunk(digest)?; let chunk = self.read_raw_chunk(digest)?;
let raw_data = chunk.decode(self.crypt_config.as_ref().map(Arc::as_ref))?; let raw_data = chunk.decode(self.crypt_config.as_ref().map(Arc::as_ref))?;