drop Cancellable future in favor of abortable
futures-0.3 has a futures::future::abortable() function which does the exact same, returns an Abortable future with an AbortHandle providing an abort() method. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
		@ -5,11 +5,11 @@ use std::sync::Arc;
 | 
			
		||||
use std::os::unix::fs::OpenOptionsExt;
 | 
			
		||||
 | 
			
		||||
use chrono::{DateTime, Utc};
 | 
			
		||||
use futures::future::AbortHandle;
 | 
			
		||||
use serde_json::{json, Value};
 | 
			
		||||
 | 
			
		||||
use proxmox::tools::digest_to_hex;
 | 
			
		||||
 | 
			
		||||
use crate::tools::futures::Canceller;
 | 
			
		||||
use crate::backup::*;
 | 
			
		||||
 | 
			
		||||
use super::{HttpClient, H2Client};
 | 
			
		||||
@ -17,21 +17,21 @@ use super::{HttpClient, H2Client};
 | 
			
		||||
/// Backup Reader
 | 
			
		||||
pub struct BackupReader {
 | 
			
		||||
    h2: H2Client,
 | 
			
		||||
    canceller: Canceller,
 | 
			
		||||
    abort: AbortHandle,
 | 
			
		||||
    crypt_config: Option<Arc<CryptConfig>>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Drop for BackupReader {
 | 
			
		||||
 | 
			
		||||
    fn drop(&mut self) {
 | 
			
		||||
        self.canceller.cancel();
 | 
			
		||||
        self.abort.abort();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl BackupReader {
 | 
			
		||||
 | 
			
		||||
    fn new(h2: H2Client, canceller: Canceller, crypt_config: Option<Arc<CryptConfig>>) -> Arc<Self> {
 | 
			
		||||
        Arc::new(Self { h2, canceller, crypt_config})
 | 
			
		||||
    fn new(h2: H2Client, abort: AbortHandle, crypt_config: Option<Arc<CryptConfig>>) -> Arc<Self> {
 | 
			
		||||
        Arc::new(Self { h2, abort, crypt_config})
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Create a new instance by upgrading the connection at '/api2/json/reader'
 | 
			
		||||
@ -54,9 +54,9 @@ impl BackupReader {
 | 
			
		||||
        });
 | 
			
		||||
        let req = HttpClient::request_builder(client.server(), "GET", "/api2/json/reader", Some(param)).unwrap();
 | 
			
		||||
 | 
			
		||||
        let (h2, canceller) = client.start_h2_connection(req, String::from(PROXMOX_BACKUP_READER_PROTOCOL_ID_V1!())).await?;
 | 
			
		||||
        let (h2, abort) = client.start_h2_connection(req, String::from(PROXMOX_BACKUP_READER_PROTOCOL_ID_V1!())).await?;
 | 
			
		||||
 | 
			
		||||
        Ok(BackupReader::new(h2, canceller, crypt_config))
 | 
			
		||||
        Ok(BackupReader::new(h2, abort, crypt_config))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Execute a GET request
 | 
			
		||||
@ -119,7 +119,7 @@ impl BackupReader {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn force_close(self) {
 | 
			
		||||
        self.canceller.cancel();
 | 
			
		||||
        self.abort.abort();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Download backup manifest (index.json)
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ use failure::*;
 | 
			
		||||
use chrono::{DateTime, Utc};
 | 
			
		||||
use futures::*;
 | 
			
		||||
use futures::stream::Stream;
 | 
			
		||||
use futures::future::AbortHandle;
 | 
			
		||||
use serde_json::{json, Value};
 | 
			
		||||
use tokio::io::AsyncReadExt;
 | 
			
		||||
use tokio::sync::{mpsc, oneshot};
 | 
			
		||||
@ -14,19 +15,18 @@ use proxmox::tools::digest_to_hex;
 | 
			
		||||
 | 
			
		||||
use super::merge_known_chunks::{MergedChunkInfo, MergeKnownChunks};
 | 
			
		||||
use crate::backup::*;
 | 
			
		||||
use crate::tools::futures::Canceller;
 | 
			
		||||
 | 
			
		||||
use super::{HttpClient, H2Client};
 | 
			
		||||
 | 
			
		||||
pub struct BackupWriter {
 | 
			
		||||
    h2: H2Client,
 | 
			
		||||
    canceller: Canceller,
 | 
			
		||||
    abort: AbortHandle,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Drop for BackupWriter {
 | 
			
		||||
 | 
			
		||||
    fn drop(&mut self) {
 | 
			
		||||
        self.canceller.cancel();
 | 
			
		||||
        self.abort.abort();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -37,8 +37,8 @@ pub struct BackupStats {
 | 
			
		||||
 | 
			
		||||
impl BackupWriter {
 | 
			
		||||
 | 
			
		||||
    fn new(h2: H2Client, canceller: Canceller) -> Arc<Self> {
 | 
			
		||||
        Arc::new(Self { h2, canceller })
 | 
			
		||||
    fn new(h2: H2Client, abort: AbortHandle) -> Arc<Self> {
 | 
			
		||||
        Arc::new(Self { h2, abort })
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn start(
 | 
			
		||||
@ -61,9 +61,9 @@ impl BackupWriter {
 | 
			
		||||
        let req = HttpClient::request_builder(
 | 
			
		||||
            client.server(), "GET", "/api2/json/backup", Some(param)).unwrap();
 | 
			
		||||
 | 
			
		||||
        let (h2, canceller) = client.start_h2_connection(req, String::from(PROXMOX_BACKUP_PROTOCOL_ID_V1!())).await?;
 | 
			
		||||
        let (h2, abort) = client.start_h2_connection(req, String::from(PROXMOX_BACKUP_PROTOCOL_ID_V1!())).await?;
 | 
			
		||||
 | 
			
		||||
        Ok(BackupWriter::new(h2, canceller))
 | 
			
		||||
        Ok(BackupWriter::new(h2, abort))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn get(
 | 
			
		||||
@ -129,13 +129,13 @@ impl BackupWriter {
 | 
			
		||||
 | 
			
		||||
        h2.post("finish", None)
 | 
			
		||||
            .map_ok(move |_| {
 | 
			
		||||
                self.canceller.cancel();
 | 
			
		||||
                self.abort.abort();
 | 
			
		||||
            })
 | 
			
		||||
            .await
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn cancel(&self) {
 | 
			
		||||
        self.canceller.cancel();
 | 
			
		||||
        self.abort.abort();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn upload_blob<R: std::io::Read>(
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,6 @@ use proxmox::tools::{
 | 
			
		||||
 | 
			
		||||
use super::pipe_to_stream::PipeToSendStream;
 | 
			
		||||
use crate::tools::async_io::EitherStream;
 | 
			
		||||
use crate::tools::futures::{cancellable, Canceller};
 | 
			
		||||
use crate::tools::{self, tty, BroadcastFuture, DEFAULT_ENCODE_SET};
 | 
			
		||||
 | 
			
		||||
#[derive(Clone)]
 | 
			
		||||
@ -287,7 +286,7 @@ impl HttpClient {
 | 
			
		||||
        &self,
 | 
			
		||||
        mut req: Request<Body>,
 | 
			
		||||
        protocol_name: String,
 | 
			
		||||
    ) -> Result<(H2Client, Canceller), Error> {
 | 
			
		||||
    ) -> Result<(H2Client, futures::future::AbortHandle), Error> {
 | 
			
		||||
 | 
			
		||||
        let auth = self.login().await?;
 | 
			
		||||
        let client = self.client.clone();
 | 
			
		||||
@ -323,7 +322,7 @@ impl HttpClient {
 | 
			
		||||
        let connection = connection
 | 
			
		||||
            .map_err(|_| panic!("HTTP/2.0 connection failed"));
 | 
			
		||||
 | 
			
		||||
        let (connection, canceller) = cancellable(connection)?;
 | 
			
		||||
        let (connection, abort) = futures::future::abortable(connection);
 | 
			
		||||
        // A cancellable future returns an Option which is None when cancelled and
 | 
			
		||||
        // Some when it finished instead, since we don't care about the return type we
 | 
			
		||||
        // need to map it away:
 | 
			
		||||
@ -334,7 +333,7 @@ impl HttpClient {
 | 
			
		||||
 | 
			
		||||
        // Wait until the `SendRequest` handle has available capacity.
 | 
			
		||||
        let c = h2.ready().await?;
 | 
			
		||||
        Ok((H2Client::new(c), canceller))
 | 
			
		||||
        Ok((H2Client::new(c), abort))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async fn credentials(
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user