From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 291051FF168 for ; Tue, 12 Nov 2024 11:44:02 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 980DC1D866; Tue, 12 Nov 2024 11:44:02 +0100 (CET) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Tue, 12 Nov 2024 11:43:14 +0100 Message-Id: <20241112104316.206282-3-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241112104316.206282-1-c.ebner@proxmox.com> References: <20241112104316.206282-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. 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 v6 proxmox-backup 2/4] pxar: bin: use dedicated api type for restore pattern 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: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Instead of taking a plain string as input parameter, use the corresponding api type performing additional input validation. Signed-off-by: Christian Ebner --- changes since version 5: - rebased to current master pxar-bin/Cargo.toml | 1 + pxar-bin/src/main.rs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pxar-bin/Cargo.toml b/pxar-bin/Cargo.toml index d0d7ab24d..37c980e28 100644 --- a/pxar-bin/Cargo.toml +++ b/pxar-bin/Cargo.toml @@ -25,5 +25,6 @@ proxmox-router = { workspace = true, features = ["cli", "server"] } proxmox-schema = { workspace = true, features = [ "api-macro" ] } proxmox-sys.workspace = true +pbs-api-types.workspace = true pbs-client.workspace = true pbs-pxar-fuse.workspace = true diff --git a/pxar-bin/src/main.rs b/pxar-bin/src/main.rs index 2fc0d1bb5..eb3580d92 100644 --- a/pxar-bin/src/main.rs +++ b/pxar-bin/src/main.rs @@ -9,9 +9,11 @@ use std::sync::Arc; use anyhow::{bail, format_err, Error}; use futures::future::FutureExt; use futures::select; +use serde_json::Value; use tokio::signal::unix::{signal, SignalKind}; use pathpatterns::{MatchEntry, MatchType, PatternFlag}; +use pbs_api_types::PathPatterns; use pbs_client::pxar::tools::format_single_line_entry; use pbs_client::pxar::{ Flags, OverwriteFlags, PxarExtractOptions, PxarWriters, ENCODER_MAX_ENTRIES, @@ -53,12 +55,7 @@ fn extract_archive_from_reader( description: "Archive name.", }, pattern: { - description: "List of paths or pattern matching files to restore", - type: Array, - items: { - type: String, - description: "Path or pattern matching files to restore.", - }, + type: PathPatterns, optional: true, }, target: { @@ -144,7 +141,6 @@ fn extract_archive_from_reader( #[allow(clippy::too_many_arguments)] fn extract_archive( archive: String, - pattern: Option>, target: Option, no_xattrs: bool, no_fcaps: bool, @@ -161,6 +157,7 @@ fn extract_archive( strict: bool, payload_input: Option, prelude_target: Option, + param: Value, ) -> Result<(), Error> { let mut feature_flags = Flags::DEFAULT; if no_xattrs { @@ -190,7 +187,6 @@ fn extract_archive( overwrite_flags.insert(OverwriteFlags::all()); } - let pattern = pattern.unwrap_or_default(); let target = target.as_ref().map_or_else(|| ".", String::as_str); let mut match_list = Vec::new(); @@ -204,11 +200,15 @@ fn extract_archive( } } - for entry in pattern { - match_list.push( - MatchEntry::parse_pattern(entry, PatternFlag::PATH_NAME, MatchType::Include) - .map_err(|err| format_err!("error in pattern: {}", err))?, - ); + if let Some(pattern) = param["pattern"].as_array() { + for p in pattern { + if let Some(entry) = p.as_str() { + match_list.push( + MatchEntry::parse_pattern(entry, PatternFlag::PATH_NAME, MatchType::Include) + .map_err(|err| format_err!("error in pattern: {err}"))?, + ); + } + } } let extract_match_default = match_list.is_empty(); -- 2.39.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel