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 DBA961FF390 for ; Fri, 7 Jun 2024 12:24:22 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A3A421CD19; Fri, 7 Jun 2024 12:24:55 +0200 (CEST) Date: Fri, 07 Jun 2024 12:24:18 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox Backup Server development discussion References: <20240607094313.178742-1-c.ebner@proxmox.com> <20240607094313.178742-6-c.ebner@proxmox.com> In-Reply-To: <20240607094313.178742-6-c.ebner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1717755817.ebwtwx0x31.astroid@yuna.none> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.058 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: Re: [pbs-devel] [PATCH proxmox-backup 5/8] 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" On June 7, 2024 11:43 am, Christian Ebner wrote: > 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 | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs > index e25a78bca..d33422d13 100644 > --- a/src/api2/admin/datastore.rs > +++ b/src/api2/admin/datastore.rs > @@ -1773,6 +1773,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("Base64 encoded archive name").schema()), same question here - this should be safe as regular string with the appropriate schema? > ]), > ) > ).access( > @@ -1840,9 +1841,17 @@ 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 = base64::decode(archive_name) > + .map_err(|err| format_err!("base64 decode of archive-name failed - {err}"))?; > + (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) { > @@ -1865,7 +1874,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 > > > _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel