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 B9947903E0 for ; Wed, 24 Jan 2024 11:15:29 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 956659F8B for ; Wed, 24 Jan 2024 11:15:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 for ; Wed, 24 Jan 2024 11:15:28 +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 3BA0349268 for ; Wed, 24 Jan 2024 11:15:28 +0100 (CET) From: Filip Schauer To: pbs-devel@lists.proxmox.com Date: Wed, 24 Jan 2024 11:15:18 +0100 Message-Id: <20240124101519.30079-5-f.schauer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240124101519.30079-1-f.schauer@proxmox.com> References: <20240124101519.30079-1-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.131 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 v4 backup 1/2] pxar: Adopt FileType enum when adding a zip entry 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: Wed, 24 Jan 2024 10:15:29 -0000 Use a FileType enum instead of a boolean to specify whether a ZipEntry is a directory or a regular file. Signed-off-by: Filip Schauer --- pbs-client/src/pxar/extract.rs | 48 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs index af18ecfc..a7f94bf6 100644 --- a/pbs-client/src/pxar/extract.rs +++ b/pbs-client/src/pxar/extract.rs @@ -24,7 +24,7 @@ use proxmox_io::{sparse_copy, sparse_copy_async}; use proxmox_sys::c_result; use proxmox_sys::fs::{create_path, CreateOptions}; -use proxmox_compression::zip::{ZipEncoder, ZipEntry}; +use proxmox_compression::zip::{FileType, ZipEncoder}; use crate::pxar::dir_stack::PxarDirStack; use crate::pxar::metadata; @@ -993,13 +993,13 @@ where let path = entry.path().strip_prefix(&prefix)?; if path != Path::new("/") { let metadata = entry.metadata(); - let entry = ZipEntry::new( + zip.add_entry( path, metadata.stat.mtime.secs, metadata.stat.mode as u16, - false, - ); - zip.add_entry::>(entry, None).await?; + FileType::>::Directory, + ) + .await?; } let mut decoder = dir.decode_full().await?; @@ -1012,15 +1012,16 @@ where match entry.kind() { EntryKind::File { .. } => { log::debug!("adding '{}' to zip", path.display()); - let entry = ZipEntry::new( - path, - metadata.stat.mtime.secs, - metadata.stat.mode as u16, - true, - ); - zip.add_entry(entry, decoder.contents()) + if let Some(contents) = decoder.contents() { + zip.add_entry( + path, + metadata.stat.mtime.secs, + metadata.stat.mode as u16, + FileType::Regular(contents), + ) .await .context("could not send file entry")?; + } } EntryKind::Hardlink(_) => { let entry = root @@ -1030,25 +1031,26 @@ where let realfile = accessor.follow_hardlink(&entry).await?; let metadata = realfile.entry().metadata(); log::debug!("adding '{}' to zip", path.display()); - let entry = ZipEntry::new( - path, - metadata.stat.mtime.secs, - metadata.stat.mode as u16, - true, - ); - zip.add_entry(entry, decoder.contents()) + if let Some(contents) = decoder.contents() { + zip.add_entry( + path, + metadata.stat.mtime.secs, + metadata.stat.mode as u16, + FileType::Regular(contents), + ) .await .context("could not send file entry")?; + } } EntryKind::Directory => { log::debug!("adding '{}' to zip", path.display()); - let entry = ZipEntry::new( + zip.add_entry( path, metadata.stat.mtime.secs, metadata.stat.mode as u16, - false, - ); - zip.add_entry::>(entry, None).await?; + FileType::>::Directory, + ) + .await?; } _ => {} // ignore all else }; -- 2.39.2