[pbs-devel] [PATCH v4 backup 1/2] pxar: Adopt FileType enum when adding a zip entry

Filip Schauer f.schauer at proxmox.com
Wed Jan 24 11:15:18 CET 2024


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 <f.schauer at proxmox.com>
---
 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::<FileContents<T>>(entry, None).await?;
+                FileType::<FileContents<T>>::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::<FileContents<T>>(entry, None).await?;
+                        FileType::<FileContents<T>>::Directory,
+                    )
+                    .await?;
                 }
                 _ => {} // ignore all else
             };
-- 
2.39.2





More information about the pbs-devel mailing list