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 6C613BBE75 for ; Wed, 20 Dec 2023 14:20:42 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 457E6D393 for ; Wed, 20 Dec 2023 14:20:12 +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, 20 Dec 2023 14:20:11 +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 06A414876C for ; Wed, 20 Dec 2023 14:20:11 +0100 (CET) Date: Wed, 20 Dec 2023 14:20:10 +0100 From: Wolfgang Bumiller To: Filip Schauer Cc: pbs-devel@lists.proxmox.com, Dominik Csapak Message-ID: References: <20231214144824.100616-1-f.schauer@proxmox.com> <20231214144824.100616-3-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214144824.100616-3-f.schauer@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.095 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 v3 proxmox 2/3] compression: Add support for symlinks in zip files 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, 20 Dec 2023 13:20:42 -0000 With the link of a symlink being encoded in the contents, I wonder if we should just do the same in the code. Not normally what I'd go for in rust, but... On Thu, Dec 14, 2023 at 03:48:21PM +0100, Filip Schauer wrote: > Add support for symlinks to ZipEntry. A symlink is encoded by or-ing its > attributes with S_IFLNK as seen in the kernel in > include/uapi/linux/stat.h > > Signed-off-by: Filip Schauer > --- > proxmox-compression/src/zip.rs | 32 +++++++++++++++++++++++++------- > 1 file changed, 25 insertions(+), 7 deletions(-) > > diff --git a/proxmox-compression/src/zip.rs b/proxmox-compression/src/zip.rs > index 069e8bc..a3b2346 100644 > --- a/proxmox-compression/src/zip.rs > +++ b/proxmox-compression/src/zip.rs > @@ -74,6 +74,7 @@ fn epoch_to_dos(epoch: i64) -> (u16, u16) { > pub enum FileType { > Directory, > Regular, > + Symlink(OsString), ... then this enum could be #[repr(u32)] using the values from the hunk below as discriminants here directly. And without the OsString in there this could be all of `Clone + Copy + Eq + PartialEq`, turning all the `matches!()` in this series into comparisons with `==`. > } > > #[derive(Endian)] > @@ -350,6 +351,7 @@ impl ZipEntry { (maybe include a comment that these are the same as the S_IF* constants, since Dominik had asked about more documentation in the previous version ;-) ) > let file_type_attr = match self.file_type { > FileType::Regular => 0o100000, > FileType::Directory => 0o040000, > + FileType::Symlink(_) => 0o120000, > }; > > write_struct( > @@ -497,22 +499,28 @@ impl ZipEncoder { > .ok_or_else(|| format_err!("had no target during add entry"))?; > entry.offset = self.byte_count.try_into()?; > self.byte_count += entry.write_local_header(&mut target).await?; > - if let Some(content) = content { > - let mut reader = HashWrapper::new(content); > + > + if content.is_some() || matches!(entry.file_type, FileType::Symlink(_)) { > let mut enc = DeflateEncoder::with_quality(target, Level::Fastest); > > - enc.compress(&mut reader).await?; > + if let Some(content) = content { > + let mut reader = HashWrapper::new(content); > + enc.compress(&mut reader).await?; > + entry.crc32 = reader.finish().0; > + } else if let FileType::Symlink(symlink_target) = &entry.file_type { > + let cursor = std::io::Cursor::new(symlink_target.as_bytes()); > + let mut reader = HashWrapper::new(cursor); > + enc.compress(&mut reader).await?; > + entry.crc32 = reader.finish().0; ^ and AFAICT this entire hunk would simply disappear? > + } > + > let total_in = enc.total_in(); > let total_out = enc.total_out(); > target = enc.into_inner(); > > - let (crc32, _reader) = reader.finish(); > - > self.byte_count += total_out as usize; > entry.compressed_size = total_out; > entry.uncompressed_size = total_in; > - > - entry.crc32 = crc32; > } > > self.byte_count += entry.write_data_descriptor(&mut target).await?; > @@ -676,6 +684,16 @@ where > let ze = ZipEntry::new(entry_path_no_base, mtime, mode, FileType::Directory); > let content: Option = None; > Ok(Some((ze, content))) > + } else if entry.file_type().is_symlink() { > + let target = std::fs::read_link(entry.path())?; > + let ze = ZipEntry::new( > + entry_path_no_base, > + mtime, > + mode, > + FileType::Symlink(target.into()), > + ); > + let content: Option = None; > + Ok(Some((ze, content))) > } else { > // ignore other file types > Ok::<_, Error>(None) > -- > 2.39.2