src/restore.rs: implement with_runtime

This commit is contained in:
Dietmar Maurer 2020-07-07 08:13:14 +02:00
parent b960af0485
commit 2b00dbce03

View File

@ -5,6 +5,7 @@ use std::convert::TryInto;
use anyhow::{format_err, bail, Error};
use once_cell::sync::OnceCell;
use tokio::runtime::Runtime;
use proxmox_backup::tools::runtime::{get_runtime, block_in_place};
use proxmox_backup::backup::*;
@ -22,7 +23,7 @@ pub struct ImageAccessInfo {
pub(crate) struct ProxmoxRestore {
setup: BackupSetup,
runtime: Arc<tokio::runtime::Runtime>,
runtime: Arc<Runtime>,
pub crypt_config: Option<Arc<CryptConfig>>,
pub client: OnceCell<Arc<BackupReader>>,
chunk_reader: OnceCell<RemoteChunkReader>,
@ -32,11 +33,11 @@ pub(crate) struct ProxmoxRestore {
impl ProxmoxRestore {
pub fn new(setup: BackupSetup) -> Result<Self, Error> {
// keep a reference to the runtime - else the runtime can be dropped
// and further connections fails.
let runtime = get_runtime();
/// Create a new instance, using the specified Runtime
///
/// We keep a reference to the runtime - else the runtime can be
/// dropped and further connections fails.
pub fn with_runtime(setup: BackupSetup, runtime: Arc<Runtime>) -> Result<Self, Error> {
let crypt_config = match setup.keyfile {
None => None,
@ -62,6 +63,11 @@ impl ProxmoxRestore {
})
}
pub fn new(setup: BackupSetup) -> Result<Self, Error> {
let runtime = get_runtime();
Self::with_runtime(setup, runtime)
}
pub async fn connect(&self) -> Result<libc::c_int, Error> {
let options = HttpClientOptions::new()