public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>,
	Max Carrara <m.carrara@proxmox.com>
Subject: Re: [pbs-devel] [PATCH v2 proxmox-backup 4/5] proxmox-backup-client: restore: add 'ignore-extract-device-errors' flag
Date: Thu, 13 Jul 2023 09:52:53 +0200	[thread overview]
Message-ID: <dimadx7gnlknk7u7cqpqlloat5zzkwdoidwbyjys4z5r4rydtz@tlm3x6m4vwyn> (raw)
In-Reply-To: <20230712130044.1611784-5-m.carrara@proxmox.com>


On Wed, Jul 12, 2023 at 03:00:43PM +0200, Max Carrara wrote:
> If this flag is provided, any errors that occur during the extraction
> of a device node are silently ignored.
>
> Signed-off-by: Max Carrara <m.carrara@proxmox.com>
> ---
>  Changes v1 --> v2:
>   * Remove unnecessary "future-proofing" that merges many error handlers into one
>
>  proxmox-backup-client/src/main.rs | 32 ++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
> index 1a6114b1..c7f90109 100644
> --- a/proxmox-backup-client/src/main.rs
> +++ b/proxmox-backup-client/src/main.rs
>
> [..]
>
> @@ -1245,6 +1252,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)?;
>
> @@ -1365,12 +1373,34 @@ async fn restore(
>
>          let mut reader = BufferedDynamicReader::new(index, chunk_reader);
>
> +        let on_error = if ignore_extract_device_errors {
> +            let handler: PxarErrorHandler = Box::new(move |err: Error| {
> +                use pbs_client::pxar::PxarExtractContext;
> +
> +                let ctx = err.downcast_ref::<PxarExtractContext>();
> +
> +                if ctx.is_none() {
> +                    return Err(err);
> +                }
> +
> +                if matches!(ctx.unwrap(), PxarExtractContext::ExtractDevice) {
> +                    return Ok(());
> +                }
> +
> +                Err(err)
> +            });
> +
> +            Some(handler)
Couldn't this be a lot simpler written as:

Some(Box::new(move |err: Error| {
    use pbs_client::pxar::PxarExtractContext;

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

(untested; just off the top of my head)

> +        } else {
> +            None
> +        };
> +
>          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.39.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-13  7:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-12 13:00 [pbs-devel] [PATCH v2 proxmox-backup/pve-container 0/5] improve error handling of pxar extractor Max Carrara
2023-07-12 13:00 ` [pbs-devel] [PATCH v2 proxmox-backup 1/5] pbs-client: pxar: preserve error context Max Carrara
2023-07-12 13:00 ` [pbs-devel] [PATCH v2 proxmox-backup 2/5] pbs-client: pxar: refactor body of `extract_archive` to `ExtractorIter` Max Carrara
2023-07-12 13:00 ` [pbs-devel] [PATCH v2 proxmox-backup 3/5] pbs-client: pxar: add PxarExtractContext Max Carrara
2023-07-12 13:00 ` [pbs-devel] [PATCH v2 proxmox-backup 4/5] proxmox-backup-client: restore: add 'ignore-extract-device-errors' flag Max Carrara
2023-07-13  7:52   ` Christoph Heiss [this message]
2023-07-13  8:06     ` Max Carrara
2023-07-12 13:00 ` [pbs-devel] [PATCH v2 pve-container 5/5] fix #3460: restore: honor '--ignore-unpack-errors' flag for pbs Max Carrara

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=dimadx7gnlknk7u7cqpqlloat5zzkwdoidwbyjys4z5r4rydtz@tlm3x6m4vwyn \
    --to=c.heiss@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