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 D5B0C9B9F5 for ; Tue, 21 Nov 2023 11:53:09 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B2CC56DE2 for ; Tue, 21 Nov 2023 11:52:39 +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 ; Tue, 21 Nov 2023 11:52:38 +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 E388140EA5 for ; Tue, 21 Nov 2023 11:52:37 +0100 (CET) Date: Tue, 21 Nov 2023 11:52:36 +0100 (CET) From: Christian Ebner To: Proxmox Backup Server development discussion , Filip Schauer Message-ID: <261276644.416.1700563956880@webmail.proxmox.com> In-Reply-To: <20231120115930.60210-2-f.schauer@proxmox.com> References: <20231120115930.60210-1-f.schauer@proxmox.com> <20231120115930.60210-2-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.6-Rev54 X-Originating-Client: open-xchange-appsuite X-SPAM-LEVEL: Spam detection results: 0 AWL 0.054 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 1/1] fix #4995: compression: Include symlinks in zip 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: , X-List-Received-Date: Tue, 21 Nov 2023 10:53:09 -0000 Does not compile, see comments inline. > On 20.11.2023 12:59 CET Filip Schauer wrote: > > > Signed-off-by: Filip Schauer > --- > proxmox-compression/src/zip.rs | 46 ++++++++++++++++++++++++++-------- > 1 file changed, 35 insertions(+), 11 deletions(-) > > diff --git a/proxmox-compression/src/zip.rs b/proxmox-compression/src/zip.rs > index d2d3fd8..89b079b 100644 > --- a/proxmox-compression/src/zip.rs > +++ b/proxmox-compression/src/zip.rs > @@ -204,6 +204,7 @@ pub struct ZipEntry { > offset: u64, > is_file: bool, > is_utf8_filename: bool, > + symlink_target: Option, > } > > impl ZipEntry { > @@ -211,7 +212,13 @@ impl ZipEntry { > /// > /// if is_file is false the path will contain an 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, > + is_file: bool, > + symlink_target: Option<&Path>, You can use `P` instead of the Path reference here, to be consistent with `path`. This will require you to take it `as_ref()` below. > + ) -> Self { > let mut relpath = PathBuf::new(); > > for comp in path.as_ref().components() { > @@ -226,6 +233,7 @@ impl ZipEntry { > > let filename: OsString = relpath.into(); > let is_utf8_filename = filename.to_str().is_some(); > + let symlink_target_osstr = symlink_target.map(|x| x.into()); As mentioned above, when of type `P`, take x.as_ref().into() to get the OsString > > Self { > filename, > @@ -237,6 +245,7 @@ impl ZipEntry { > offset: 0, > is_file, > is_utf8_filename, > + symlink_target: symlink_target_osstr, > } > } > > @@ -360,7 +369,9 @@ 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) << 16 > + | (self.symlink_target.is_some() as u32) << 5, Will not compile like this, the colon has to be after the next line. > + | (!self.is_file as u32) << 4 > offset, > }, > ) > @@ -486,23 +497,30 @@ 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 entry.symlink_target.is_some() || content.is_some() { I would check for content.is_some() first, as it is more likely to have a regular file as opposed to as symlink > let mut enc = DeflateEncoder::with_quality(target, Level::Fastest); > > - enc.compress(&mut reader).await?; > + if let Some(symlink_target) = entry.symlink_target.as_ref() { > + 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; > + } else if let Some(content) = content { Same, check for content before checking for symlink > + let mut reader = HashWrapper::new(content); > + enc.compress(&mut reader).await?; > + entry.crc32 = reader.finish().0; > + } > + > 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?; > self.target = Some(target); > > @@ -658,10 +676,16 @@ 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, true, None); > 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, false, None); > + 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, true, Some(target.as_ref())); > let content: Option = None; > Ok(Some((ze, content))) > } else { > -- > 2.39.2