src/backup/read_chunk.rs: move read chunk trait into extra file
And implement LocalChunkReader.
This commit is contained in:
parent
8fad30a4b1
commit
b850673634
@ -135,6 +135,9 @@ pub use chunk_stat::*;
|
|||||||
|
|
||||||
pub use proxmox_protocol::Chunker;
|
pub use proxmox_protocol::Chunker;
|
||||||
|
|
||||||
|
mod read_chunk;
|
||||||
|
pub use read_chunk::*;
|
||||||
|
|
||||||
mod chunk_store;
|
mod chunk_store;
|
||||||
pub use chunk_store::*;
|
pub use chunk_store::*;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use crate::tools;
|
|||||||
use super::IndexFile;
|
use super::IndexFile;
|
||||||
use super::chunk_stat::*;
|
use super::chunk_stat::*;
|
||||||
use super::chunk_store::*;
|
use super::chunk_store::*;
|
||||||
|
use super::read_chunk::*;
|
||||||
use proxmox_protocol::Chunker;
|
use proxmox_protocol::Chunker;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -243,12 +244,6 @@ impl IndexFile for DynamicIndexReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The ReadChunk trait allows reading backup data chunks (local or remote)
|
|
||||||
pub trait ReadChunk {
|
|
||||||
/// Returns the decoded chunk data
|
|
||||||
fn read_chunk(&self, digest:&[u8; 32]) -> Result<Vec<u8>, Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct BufferedDynamicReader<S> {
|
pub struct BufferedDynamicReader<S> {
|
||||||
store: S,
|
store: S,
|
||||||
index: DynamicIndexReader,
|
index: DynamicIndexReader,
|
||||||
|
45
src/backup/read_chunk.rs
Normal file
45
src/backup/read_chunk.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
use failure::*;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use super::datastore::*;
|
||||||
|
use super::crypt_config::*;
|
||||||
|
use super::data_chunk::*;
|
||||||
|
|
||||||
|
/// The ReadChunk trait allows reading backup data chunks (local or remote)
|
||||||
|
pub trait ReadChunk {
|
||||||
|
/// Returns the decoded chunk data
|
||||||
|
fn read_chunk(&self, digest:&[u8; 32]) -> Result<Vec<u8>, Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LocalChunkReader {
|
||||||
|
store: DataStore,
|
||||||
|
crypt_config: Option<Arc<CryptConfig>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LocalChunkReader {
|
||||||
|
|
||||||
|
pub fn new(store: DataStore, crypt_config: Option<Arc<CryptConfig>>) -> Self {
|
||||||
|
Self { store, crypt_config }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReadChunk for LocalChunkReader {
|
||||||
|
|
||||||
|
fn read_chunk(&self, digest:&[u8; 32]) -> Result<Vec<u8>, Error> {
|
||||||
|
|
||||||
|
let digest_str = proxmox::tools::digest_to_hex(digest);
|
||||||
|
println!("READ CHUNK {}", digest_str);
|
||||||
|
|
||||||
|
let (path, _) = self.store.chunk_path(digest);
|
||||||
|
let raw_data = crate::tools::file_get_contents(&path)?;
|
||||||
|
let chunk = DataChunk::from_raw(raw_data, *digest)?;
|
||||||
|
chunk.verify_crc()?;
|
||||||
|
|
||||||
|
let raw_data = match self.crypt_config {
|
||||||
|
Some(ref crypt_config) => chunk.decode(Some(crypt_config))?,
|
||||||
|
None => chunk.decode(None)?,
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(raw_data)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user