more cleanup

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-06-12 11:01:04 +02:00
parent 1498659b4e
commit a609cf210e

View File

@ -1,10 +1,10 @@
use std::collections::HashMap;
use std::sync::Arc;
use anyhow::{Error};
use anyhow::Error;
use super::BackupReader;
use crate::backup::{ReadChunk, DataBlob, CryptConfig};
use crate::backup::{CryptConfig, DataBlob, ReadChunk};
use crate::tools::runtime::block_on;
/// Read chunks from remote host using ``BackupReader``
@ -16,7 +16,6 @@ pub struct RemoteChunkReader {
}
impl RemoteChunkReader {
/// Create a new instance.
///
/// Chunks listed in ``cache_hint`` are cached and kept in RAM.
@ -25,16 +24,18 @@ impl RemoteChunkReader {
crypt_config: Option<Arc<CryptConfig>>,
cache_hint: HashMap<[u8; 32], usize>,
) -> Self {
Self { client, crypt_config, cache_hint, cache: HashMap::new() }
Self {
client,
crypt_config,
cache_hint,
cache: HashMap::new(),
}
}
}
impl ReadChunk for RemoteChunkReader {
fn read_raw_chunk(&mut self, digest:&[u8; 32]) -> Result<DataBlob, Error> {
let mut chunk_data = Vec::with_capacity(4*1024*1024);
fn read_raw_chunk(&mut self, digest: &[u8; 32]) -> Result<DataBlob, Error> {
let mut chunk_data = Vec::with_capacity(4 * 1024 * 1024);
//tokio::task::block_in_place(|| futures::executor::block_on(self.client.download_chunk(&digest, &mut chunk_data)))?;
block_on(async {
@ -51,8 +52,7 @@ impl ReadChunk for RemoteChunkReader {
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> {
if let Some(raw_data) = self.cache.get(digest) {
return Ok(raw_data.to_vec());
}
@ -70,5 +70,4 @@ impl ReadChunk for RemoteChunkReader {
Ok(raw_data)
}
}