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 607F41FF399 for ; Fri, 7 Jun 2024 13:37:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 109931E081; Fri, 7 Jun 2024 13:38:08 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Fri, 7 Jun 2024 13:37:48 +0200 Message-Id: <20240607113752.324017-6-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240607113752.324017-1-c.ebner@proxmox.com> References: <20240607113752.324017-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH v2 proxmox-backup 5/9] api: datastore: add optional archive-name to file-restore 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" Allow to pass the archive name as optional api call parameter instead of having it as prefix to the path. If this parameter is given, instead of splitting of the archive name from the path, the parameter itself is used, leaving the path untouched. This allows to restore single files from the archive, without having to artificially construct the path in case of file restores for split pxar archives, where the response path of the listing does not include the archive, as opposed to the response provided by lookup via the catalog. Signed-off-by: Christian Ebner --- src/api2/admin/datastore.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index b90302966..225ff6fec 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -1766,6 +1766,7 @@ pub const API_METHOD_PXAR_FILE_DOWNLOAD: ApiMethod = ApiMethod::new( ("backup-time", false, &BACKUP_TIME_SCHEMA), ("filepath", false, &StringSchema::new("Base64 encoded path").schema()), ("tar", true, &BooleanSchema::new("Download as .tar.zst").schema()), + ("archive-name", true, &StringSchema::new("Archive name").schema()), ]), ) ).access( @@ -1833,9 +1834,16 @@ pub fn pxar_file_download( components.remove(0); } - let mut split = components.splitn(2, |c| *c == b'/'); - let pxar_name = std::str::from_utf8(split.next().unwrap())?; - let file_path = split.next().unwrap_or(b"/"); + let (pxar_name, file_path) = if let Some(archive_name) = param["archive-name"].as_str() { + let archive_name = archive_name.as_bytes().to_owned(); + (archive_name, base64::decode(&filepath)?) + } else { + let mut split = components.splitn(2, |c| *c == b'/'); + let pxar_name = split.next().unwrap(); + let file_path = split.next().unwrap_or(b"/"); + (pxar_name.to_owned(), file_path.to_owned()) + }; + let pxar_name = std::str::from_utf8(&pxar_name)?; let (manifest, files) = read_backup_index(&backup_dir)?; for file in files { if file.filename == pxar_name && file.crypt_mode == Some(CryptMode::Encrypt) { @@ -1858,7 +1866,7 @@ pub fn pxar_file_download( let decoder = Accessor::new(reader, archive_size).await?; let root = decoder.open_root().await?; - let path = OsStr::from_bytes(file_path).to_os_string(); + let path = OsStr::from_bytes(&file_path).to_os_string(); let file = root .lookup(&path) .await? -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel