public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Max Carrara <m.carrara@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox-backup 4/5] proxmox-backup-client: restore: add 'ignore-extract-device-errors' flag
Date: Tue, 11 Jul 2023 16:17:53 +0200	[thread overview]
Message-ID: <7n2bmkf3xbyj5j2h6airezs24dyaoy2fi6ugiuqzqisrjcqkwv@hej4yopid2s4> (raw)
In-Reply-To: <20230607163428.1154123-5-m.carrara@proxmox.com>

On Wed, Jun 07, 2023 at 06:34:27PM +0200, Max Carrara wrote:
> If this flag is provided, any errors that occur during the extraction
> of a device node are silently ignored.
> 
> In addition to this flag and its error handler, the bare scaffold
> for supporting multiple error handlers is also added.
> 
> Signed-off-by: Max Carrara <m.carrara@proxmox.com>
> ---
> 
> Notes:
>   One thing I'm not *really* sure about here is the name of the CLI
>   flag - to me it feels a little bit too verbose, but it does exactly
>   what it says.
> 
>  proxmox-backup-client/src/main.rs | 61 ++++++++++++++++++++++++++++++-
>  1 file changed, 60 insertions(+), 1 deletion(-)
> 
> diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
> index 55198108..1fb8a378 100644
> --- a/proxmox-backup-client/src/main.rs
> +++ b/proxmox-backup-client/src/main.rs
> @@ -29,6 +29,7 @@ use pbs_api_types::{
>      BACKUP_TYPE_SCHEMA, TRAFFIC_CONTROL_BURST_SCHEMA, TRAFFIC_CONTROL_RATE_SCHEMA,
>  };
>  use pbs_client::catalog_shell::Shell;
> +use pbs_client::pxar::ErrorHandler as PxarErrorHandler;
>  use pbs_client::tools::{
>      complete_archive_name, complete_auth_id, complete_backup_group, complete_backup_snapshot,
>      complete_backup_source, complete_chunk_size, complete_group_or_snapshot,
> @@ -1232,6 +1233,12 @@ We do not extract '.pxar' archives when writing to standard output.
>                  optional: true,
>                  default: false,
>              },
> +            "ignore-extract-device-errors": {
> +                type: Boolean,
> +                description: "ignore errors that occur during device node extraction",
> +                optional: true,
> +                default: false,
> +            }
>          }
>      }
>  )]
> @@ -1244,6 +1251,7 @@ async fn restore(
>      ignore_ownership: bool,
>      ignore_permissions: bool,
>      overwrite: bool,
> +    ignore_extract_device_errors: bool,
>  ) -> Result<Value, Error> {
>      let repo = extract_repository_from_value(&param)?;
>  
> @@ -1364,12 +1372,63 @@ async fn restore(
>  
>          let mut reader = BufferedDynamicReader::new(index, chunk_reader);
>  
> +        fn make_handler_from_many<I>(handlers: I) -> PxarErrorHandler
> +        where
> +            I: IntoIterator<Item = PxarErrorHandler>,
> +        {
> +            let mut captured_handlers: Vec<PxarErrorHandler> = handlers.into_iter().collect();
> +
> +            let handler: PxarErrorHandler = Box::new(move |error: Error| -> Result<(), Error> {
> +                let mut res = Err(error);
> +
> +                for handler in captured_handlers.iter_mut() {
> +                    if let Err(error) = res {
> +                        res = handler(error);
> +                    } else {
> +                        return res;
> +                    }
> +                }
> +
> +                res
> +            });
> +
> +            handler
> +        }
> +
> +        let mut handlers: Vec<PxarErrorHandler> = Vec::new();
> +
> +        if ignore_extract_device_errors {
> +            let on_device_error = Box::new(move |err: Error| {
> +                use pbs_client::pxar::PxarExtractContext;
> +
> +                let ctx = err.downcast_ref::<PxarExtractContext>();
> +
> +                if ctx.is_none() {

Another `is_none()` check + unwrap.

How about

    match err.downcast_ref::<PxarExtractContext>() {
        Some(PxarExtractContext::ExtractDevice) => Ok(()),
        _ => Err(err),
    )

? :)

> +                    return Err(err);
> +                }
> +
> +                if matches!(ctx.unwrap(), PxarExtractContext::ExtractDevice) {
> +                    return Ok(());
> +                }
> +
> +                Err(err)
> +            });
> +
> +            handlers.push(on_device_error);
> +        }
> +
> +        let on_error = if handlers.is_empty() {
> +            None
> +        } else {
> +            Some(make_handler_from_many(handlers))
> +        };
> +
>          let options = pbs_client::pxar::PxarExtractOptions {
>              match_list: &[],
>              extract_match_default: true,
>              allow_existing_dirs,
>              overwrite,
> -            on_error: None,
> +            on_error,
>          };
>  
>          let mut feature_flags = pbs_client::pxar::Flags::DEFAULT;
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
> 




  reply	other threads:[~2023-07-11 14:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07 16:34 [pbs-devel] [PATCH proxmox-backup/pve-container 0/5] improve error handling of pxar extractor Max Carrara
2023-06-07 16:34 ` [pbs-devel] [PATCH proxmox-backup 1/5] pbs-client: pxar: preserve error context Max Carrara
2023-07-11 12:54   ` Wolfgang Bumiller
2023-06-07 16:34 ` [pbs-devel] [PATCH proxmox-backup 2/5] pbs-client: pxar: refactor body of `extract_archive` to `ExtractorIter` Max Carrara
2023-07-11 13:24   ` Wolfgang Bumiller
2023-06-07 16:34 ` [pbs-devel] [PATCH proxmox-backup 3/5] pbs-client: pxar: add `PxarExtractContext` Max Carrara
2023-06-07 16:34 ` [pbs-devel] [PATCH proxmox-backup 4/5] proxmox-backup-client: restore: add 'ignore-extract-device-errors' flag Max Carrara
2023-07-11 14:17   ` Wolfgang Bumiller [this message]
2023-06-07 16:34 ` [pbs-devel] [PATCH pve-container 5/5] fix #3460: restore: honor '--ignore-unpack-errors' flag for pbs Max Carrara
2023-06-08 13:47   ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7n2bmkf3xbyj5j2h6airezs24dyaoy2fi6ugiuqzqisrjcqkwv@hej4yopid2s4 \
    --to=w.bumiller@proxmox.com \
    --cc=m.carrara@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal