public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v4 backup 1/2] pxar: Adopt FileType enum when adding a zip entry
Date: Wed, 24 Jan 2024 11:15:18 +0100	[thread overview]
Message-ID: <20240124101519.30079-5-f.schauer@proxmox.com> (raw)
In-Reply-To: <20240124101519.30079-1-f.schauer@proxmox.com>

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@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





  parent reply	other threads:[~2024-01-24 10:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 10:15 [pbs-devel] [PATCH v4 many] fix #4995: Include symlinks in zip file restore Filip Schauer
2024-01-24 10:15 ` [pbs-devel] [PATCH v4 proxmox 1/3] compression: Refactor ZipEntry creation and add FileType enum Filip Schauer
2024-01-24 10:15 ` [pbs-devel] [PATCH v4 proxmox 2/3] compression: Add support for symlinks in zip files Filip Schauer
2024-01-24 10:15 ` [pbs-devel] [PATCH v4 proxmox 3/3] compression: Add unit tests for the ZipEncoder Filip Schauer
2024-01-24 10:15 ` Filip Schauer [this message]
2024-01-24 10:15 ` [pbs-devel] [PATCH v4 backup 2/2] fix #4995: pxar: Include symlinks in zip file creation Filip Schauer
2024-01-29 12:44 ` [pbs-devel] [PATCH v4 many] fix #4995: Include symlinks in zip file restore Folke Gleumes

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=20240124101519.30079-5-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal