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 120B4BA7FD for ; Thu, 14 Dec 2023 15:49:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C848418A76 for ; Thu, 14 Dec 2023 15:49:02 +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 ; Thu, 14 Dec 2023 15:49:01 +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 6C92C4763E for ; Thu, 14 Dec 2023 15:49:01 +0100 (CET) From: Filip Schauer To: pbs-devel@lists.proxmox.com Date: Thu, 14 Dec 2023 15:48:20 +0100 Message-Id: <20231214144824.100616-2-f.schauer@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214144824.100616-1-f.schauer@proxmox.com> References: <20231214144824.100616-1-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.157 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 v3 proxmox 1/3] compression: Add a FileType enum to ZipEntry 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: Thu, 14 Dec 2023 14:49:33 -0000 Specify the type of a ZipEntry with a new FileType enum instead of a boolean is_file. Signed-off-by: Filip Schauer --- proxmox-compression/src/zip.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/proxmox-compression/src/zip.rs b/proxmox-compression/src/zip.rs index d2d3fd8..069e8bc 100644 --- a/proxmox-compression/src/zip.rs +++ b/proxmox-compression/src/zip.rs @@ -71,6 +71,11 @@ fn epoch_to_dos(epoch: i64) -> (u16, u16) { (date, time) } +pub enum FileType { + Directory, + Regular, +} + #[derive(Endian)] #[repr(C, packed)] struct Zip64Field { @@ -202,16 +207,16 @@ pub struct ZipEntry { uncompressed_size: u64, compressed_size: u64, offset: u64, - is_file: bool, + file_type: FileType, is_utf8_filename: bool, } impl ZipEntry { /// Creates a new ZipEntry /// - /// if is_file is false the path will contain an trailing separator, + /// if file is a directory the path will contain a trailing separator, /// so that the zip file understands that it is a directory - pub fn new>(path: P, mtime: i64, mode: u16, is_file: bool) -> Self { + pub fn new>(path: P, mtime: i64, mode: u16, file_type: FileType) -> Self { let mut relpath = PathBuf::new(); for comp in path.as_ref().components() { @@ -220,7 +225,7 @@ impl ZipEntry { } } - if !is_file { + if matches!(file_type, FileType::Directory) { relpath.push(""); // adds trailing slash } @@ -235,7 +240,7 @@ impl ZipEntry { uncompressed_size: 0, compressed_size: 0, offset: 0, - is_file, + file_type, is_utf8_filename, } } @@ -342,6 +347,11 @@ impl ZipEntry { ) }; + let file_type_attr = match self.file_type { + FileType::Regular => 0o100000, + FileType::Directory => 0o040000, + }; + write_struct( &mut buf, CentralDirectoryFileHeader { @@ -360,7 +370,8 @@ impl ZipEntry { comment_len: 0, start_disk: 0, internal_flags: 0, - external_flags: (self.mode as u32) << 16 | (!self.is_file as u32) << 4, + external_flags: (self.mode as u32 | file_type_attr) << 16 + | (matches!(self.file_type, FileType::Directory) as u32) << 4, offset, }, ) @@ -449,7 +460,7 @@ where /// "foo.txt", /// 0, /// 0o100755, -/// true, +/// FileType::Regular, /// ), Some(source)).await?; /// /// zip.finish().await?; @@ -503,6 +514,7 @@ impl ZipEncoder { entry.crc32 = crc32; } + self.byte_count += entry.write_data_descriptor(&mut target).await?; self.target = Some(target); @@ -658,10 +670,10 @@ where if entry.file_type().is_file() { let file = tokio::fs::File::open(entry.path()).await?; - let ze = ZipEntry::new(entry_path_no_base, mtime, mode, true); + let ze = ZipEntry::new(entry_path_no_base, mtime, mode, FileType::Regular); Ok(Some((ze, Some(file)))) } else if entry.file_type().is_dir() { - let ze = ZipEntry::new(entry_path_no_base, mtime, mode, false); + let ze = ZipEntry::new(entry_path_no_base, mtime, mode, FileType::Directory); let content: Option = None; Ok(Some((ze, content))) } else { -- 2.39.2