From a80d72f99997a914fc64da390c00abb1685aa7c5 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 4 Feb 2021 07:05:43 +0100 Subject: [PATCH] tape: allow to abort restore tasks --- src/api2/tape/restore.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index 9dc1f660..96fb184d 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -25,6 +25,7 @@ use proxmox::{ use crate::{ task_log, + task::TaskState, tools::compute_file_csum, api2::types::{ DATASTORE_SCHEMA, @@ -307,7 +308,7 @@ fn restore_archive<'a>( if is_new { task_log!(worker, "restore snapshot {}", backup_dir); - match restore_snapshot_archive(reader, &path) { + match restore_snapshot_archive(worker, reader, &path) { Err(err) => { std::fs::remove_dir_all(&path)?; bail!("restore snapshot {} failed - {}", backup_dir, err); @@ -367,6 +368,9 @@ fn restore_chunk_archive<'a>( let result: Result<_, Error> = proxmox::try_block!({ while let Some((digest, blob)) = decoder.next_chunk()? { + + worker.check_abort()?; + if let Some(datastore) = datastore { let chunk_exists = datastore.cond_touch_chunk(&digest, false)?; if !chunk_exists { @@ -413,12 +417,13 @@ fn restore_chunk_archive<'a>( } fn restore_snapshot_archive<'a>( + worker: &WorkerTask, reader: Box, snapshot_path: &Path, ) -> Result { let mut decoder = pxar::decoder::sync::Decoder::from_std(reader)?; - match try_restore_snapshot_archive(&mut decoder, snapshot_path) { + match try_restore_snapshot_archive(worker, &mut decoder, snapshot_path) { Ok(()) => Ok(true), Err(err) => { let reader = decoder.input(); @@ -440,6 +445,7 @@ fn restore_snapshot_archive<'a>( } fn try_restore_snapshot_archive( + worker: &WorkerTask, decoder: &mut pxar::decoder::sync::Decoder, snapshot_path: &Path, ) -> Result<(), Error> { @@ -462,6 +468,8 @@ fn try_restore_snapshot_archive( let mut manifest = None; loop { + worker.check_abort()?; + let entry = match decoder.next() { None => break, Some(entry) => entry?,