diff --git a/src/commands.rs b/src/commands.rs index 78cf0cf..037620d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -21,7 +21,7 @@ lazy_static!{ }; } -struct ImageUploadInfo { +pub struct ImageUploadInfo { wid: u64, device_name: String, zero_chunk_digest: [u8; 32], @@ -30,34 +30,34 @@ struct ImageUploadInfo { upload_result: Option, } -pub (crate) struct ImageRegistry { - upload_info: Vec, +pub struct Registry { + pub info_list: Vec, file_list: Vec, } -impl ImageRegistry { +impl Registry { pub fn new() -> Self { Self { - upload_info: Vec::new(), + info_list: Vec::new(), file_list: Vec::new(), } } - fn register(&mut self, info: ImageUploadInfo) -> Result { - let dev_id = self.upload_info.len(); + pub fn register(&mut self, info: T) -> Result { + let dev_id = self.info_list.len(); if dev_id > 255 { - bail!("register image faild - to many images (limit is 255)"); + bail!("register failed - too many images/archives (limit is 255)"); } - self.upload_info.push(info); + self.info_list.push(info); Ok(dev_id as u8) } - fn lookup(&mut self, dev_id: u8) -> Result<&mut ImageUploadInfo, Error> { - if dev_id as usize >= self.upload_info.len() { - bail!("image lookup failed for dev_id = {}", dev_id); + pub fn lookup(&mut self, id: u8) -> Result<&mut T, Error> { + if id as usize >= self.info_list.len() { + bail!("lookup failed for id = {}", id); } - Ok(&mut self.upload_info[dev_id as usize]) + Ok(&mut self.info_list[id as usize]) } } @@ -90,7 +90,7 @@ async fn register_zero_chunk( pub(crate) async fn add_config( client: Arc, - registry: Arc>, + registry: Arc>>, name: String, data: Vec, ) -> Result { @@ -114,7 +114,7 @@ pub(crate) async fn register_image( client: Arc, crypt_config: Option>, manifest: Option>, - registry: Arc>, + registry: Arc>>, known_chunks: Arc>>, device_name: String, device_size: u64, @@ -197,7 +197,7 @@ pub(crate) async fn register_image( pub(crate) async fn close_image( client: Arc, - registry: Arc>, + registry: Arc>>, dev_id: u8, ) -> Result { @@ -255,7 +255,7 @@ pub(crate) async fn close_image( pub(crate) async fn write_data( client: Arc, crypt_config: Option>, - registry: Arc>, + registry: Arc>>, known_chunks: Arc>>, dev_id: u8, data: DataPointer, @@ -372,7 +372,7 @@ pub(crate) async fn write_data( pub(crate) async fn finish_backup( client: Arc, - registry: Arc>, + registry: Arc>>, setup: BackupSetup, ) -> Result { diff --git a/src/restore.rs b/src/restore.rs index 9da3066..e0b0926 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -1,17 +1,26 @@ use anyhow::{bail, Error}; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use proxmox_backup::tools::runtime::{get_runtime, block_on}; use proxmox_backup::backup::*; use proxmox_backup::client::{HttpClient, HttpClientOptions, BackupReader, RemoteChunkReader}; use super::BackupSetup; +use crate::commands::Registry; + +pub struct ImageAccessInfo { + pub reader: Arc, + pub index: Arc, + pub archive_name: String, + pub archive_size: u64, +} pub(crate) struct ProxmoxRestore { _runtime: Arc, pub client: Arc, pub crypt_config: Option>, pub manifest: BackupManifest, + pub registry: Arc>>, } impl ProxmoxRestore { @@ -64,6 +73,7 @@ impl ProxmoxRestore { manifest, client, crypt_config, + registry: Arc::new(Mutex::new(Registry::::new())), }) } diff --git a/src/worker_task.rs b/src/worker_task.rs index c919fa7..7e5face 100644 --- a/src/worker_task.rs +++ b/src/worker_task.rs @@ -18,7 +18,7 @@ pub(crate) struct BackupTask { crypt_config: Option>, writer: Mutex>>, last_manifest: Mutex>>, - registry: Arc>, + registry: Arc>>, known_chunks: Arc>>, abort: tokio::sync::broadcast::Sender<()>, aborted: Mutex>, // set on abort, conatins abort reason @@ -52,7 +52,7 @@ impl BackupTask { let (abort, _) = tokio::sync::broadcast::channel(16); - let registry = Arc::new(Mutex::new(ImageRegistry::new())); + let registry = Arc::new(Mutex::new(Registry::::new())); let known_chunks = Arc::new(Mutex::new(HashSet::new())); Ok(Self { runtime, setup, crypt_config, abort, registry, known_chunks,