From: Filip Schauer <f.schauer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v3 proxmox 1/3] compression: Add a FileType enum to ZipEntry
Date: Thu, 14 Dec 2023 15:48:20 +0100 [thread overview]
Message-ID: <20231214144824.100616-2-f.schauer@proxmox.com> (raw)
In-Reply-To: <20231214144824.100616-1-f.schauer@proxmox.com>
Specify the type of a ZipEntry with a new FileType enum
instead of a boolean is_file.
Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
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<P: AsRef<Path>>(path: P, mtime: i64, mode: u16, is_file: bool) -> Self {
+ pub fn new<P: AsRef<Path>>(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<W: AsyncWrite + Unpin> ZipEncoder<W> {
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<tokio::fs::File> = None;
Ok(Some((ze, content)))
} else {
--
2.39.2
next prev parent reply other threads:[~2023-12-14 14:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-14 14:48 [pbs-devel] [PATCH v3 many] fix #4995: Include symlinks in zip file restore Filip Schauer
2023-12-14 14:48 ` Filip Schauer [this message]
2023-12-14 14:48 ` [pbs-devel] [PATCH v3 proxmox 2/3] compression: Add support for symlinks in zip files Filip Schauer
2023-12-20 13:20 ` Wolfgang Bumiller
2023-12-21 11:37 ` Filip Schauer
2023-12-21 12:03 ` Wolfgang Bumiller
2023-12-21 12:15 ` Filip Schauer
2023-12-21 12:11 ` Wolfgang Bumiller
2024-01-24 10:19 ` Filip Schauer
2023-12-14 14:48 ` [pbs-devel] [PATCH v3 proxmox 3/3] compression: Add unit tests for the ZipEncoder Filip Schauer
2023-12-14 14:48 ` [pbs-devel] [PATCH v3 backup 1/2] pxar: Adopt FileType enum when creating a ZipEntry Filip Schauer
2023-12-14 14:48 ` [pbs-devel] [PATCH v3 backup 2/2] fix #4995: pxar: Include symlinks in zip file creation Filip Schauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231214144824.100616-2-f.schauer@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox