From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D9F586AEEC for ; Mon, 25 Jan 2021 14:43:40 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D7D64AEED for ; Mon, 25 Jan 2021 14:43:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 32E3CAEE3 for ; Mon, 25 Jan 2021 14:43:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id F396B4555C for ; Mon, 25 Jan 2021 14:43:39 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Mon, 25 Jan 2021 14:42:55 +0100 Message-Id: <20210125134302.3394328-11-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210125134302.3394328-1-f.gruenbichler@proxmox.com> References: <20210125134302.3394328-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 10/15] pxar: extract PxarExtractOptions X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jan 2021 13:43:40 -0000 same as PxarCreateOptions, but for extraction/restore rather than create. Signed-off-by: Fabian Grünbichler --- src/bin/proxmox-backup-client.rs | 12 ++++++++---- src/bin/pxar.rs | 31 ++++++++++++++----------------- src/pxar/extract.rs | 20 ++++++++++++-------- src/pxar/mod.rs | 2 +- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/bin/proxmox-backup-client.rs b/src/bin/proxmox-backup-client.rs index c3d6a0ed..d31e47ae 100644 --- a/src/bin/proxmox-backup-client.rs +++ b/src/bin/proxmox-backup-client.rs @@ -1354,20 +1354,24 @@ async fn restore(param: Value) -> Result { let mut reader = BufferedDynamicReader::new(index, chunk_reader); + let options = proxmox_backup::pxar::PxarExtractOptions { + match_list: &[], + extract_match_default: true, + allow_existing_dirs, + on_error: None, + }; + if let Some(target) = target { proxmox_backup::pxar::extract_archive( pxar::decoder::Decoder::from_std(reader)?, Path::new(target), - &[], - true, proxmox_backup::pxar::Flags::DEFAULT, - allow_existing_dirs, |path| { if verbose { println!("{:?}", path); } }, - None, + options, ) .map_err(|err| format_err!("error extracting archive - {}", err))?; } else { diff --git a/src/bin/pxar.rs b/src/bin/pxar.rs index 85606c1d..b2fe6d52 100644 --- a/src/bin/pxar.rs +++ b/src/bin/pxar.rs @@ -17,31 +17,26 @@ use proxmox::api::cli::*; use proxmox::api::api; use proxmox_backup::tools; -use proxmox_backup::pxar::{fuse, format_single_line_entry, ENCODER_MAX_ENTRIES, ErrorHandler, Flags}; +use proxmox_backup::pxar::{fuse, format_single_line_entry, ENCODER_MAX_ENTRIES, Flags, PxarExtractOptions}; fn extract_archive_from_reader( reader: &mut R, target: &str, feature_flags: Flags, - allow_existing_dirs: bool, verbose: bool, - match_list: &[MatchEntry], - extract_match_default: bool, - on_error: Option, + options: PxarExtractOptions, ) -> Result<(), Error> { + proxmox_backup::pxar::extract_archive( pxar::decoder::Decoder::from_std(reader)?, Path::new(target), - &match_list, - extract_match_default, feature_flags, - allow_existing_dirs, |path| { if verbose { println!("{:?}", path); } }, - on_error, + options, ) } @@ -190,6 +185,13 @@ fn extract_archive( }) as Box Result<(), Error> + Send>) }; + let options = PxarExtractOptions { + match_list: &match_list, + allow_existing_dirs, + extract_match_default, + on_error, + }; + if archive == "-" { let stdin = std::io::stdin(); let mut reader = stdin.lock(); @@ -197,11 +199,8 @@ fn extract_archive( &mut reader, &target, feature_flags, - allow_existing_dirs, verbose, - &match_list, - extract_match_default, - on_error, + options, )?; } else { if verbose { @@ -213,11 +212,8 @@ fn extract_archive( &mut reader, &target, feature_flags, - allow_existing_dirs, verbose, - &match_list, - extract_match_default, - on_error, + options, )?; } @@ -297,6 +293,7 @@ fn extract_archive( }, )] /// Create a new .pxar archive. +#[allow(clippy::too_many_arguments)] fn create_archive( archive: String, source: String, diff --git a/src/pxar/extract.rs b/src/pxar/extract.rs index e22fc847..9cf3f928 100644 --- a/src/pxar/extract.rs +++ b/src/pxar/extract.rs @@ -24,17 +24,21 @@ use crate::pxar::dir_stack::PxarDirStack; use crate::pxar::metadata; use crate::pxar::Flags; +pub struct PxarExtractOptions<'a> { + pub match_list: &'a[MatchEntry], + pub extract_match_default: bool, + pub allow_existing_dirs: bool, + pub on_error: Option, +} + pub type ErrorHandler = Box Result<(), Error> + Send>; pub fn extract_archive( mut decoder: pxar::decoder::Decoder, destination: &Path, - match_list: &[MatchEntry], - extract_match_default: bool, feature_flags: Flags, - allow_existing_dirs: bool, mut callback: F, - on_error: Option, + options: PxarExtractOptions, ) -> Result<(), Error> where T: pxar::decoder::SeqRead, @@ -69,17 +73,17 @@ where let mut extractor = Extractor::new( dir, root.metadata().clone(), - allow_existing_dirs, + options.allow_existing_dirs, feature_flags, ); - if let Some(on_error) = on_error { + if let Some(on_error) = options.on_error { extractor.on_error(on_error); } let mut match_stack = Vec::new(); let mut err_path_stack = vec![OsString::from("/")]; - let mut current_match = extract_match_default; + let mut current_match = options.extract_match_default; while let Some(entry) = decoder.next() { use pxar::EntryKind; @@ -99,7 +103,7 @@ where extractor.set_path(entry.path().as_os_str().to_owned()); - let match_result = match_list.matches( + let match_result = options.match_list.matches( entry.path().as_os_str().as_bytes(), Some(metadata.file_type() as u32), ); diff --git a/src/pxar/mod.rs b/src/pxar/mod.rs index c10bb6fb..5d03591b 100644 --- a/src/pxar/mod.rs +++ b/src/pxar/mod.rs @@ -59,7 +59,7 @@ mod flags; pub use flags::Flags; pub use create::{create_archive, PxarCreateOptions}; -pub use extract::{extract_archive, ErrorHandler}; +pub use extract::{extract_archive, ErrorHandler, PxarExtractOptions}; /// The format requires to build sorted directory lookup tables in /// memory, so we restrict the number of allowed entries to limit -- 2.20.1