all lists on 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 proxmox v5 2/5] compression: zip: add support for symlinks
Date: Mon, 27 Oct 2025 14:24:44 +0100	[thread overview]
Message-ID: <20251027132450.101103-3-f.schauer@proxmox.com> (raw)
In-Reply-To: <20251027132450.101103-1-f.schauer@proxmox.com>

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 proxmox-compression/src/zip.rs | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/proxmox-compression/src/zip.rs b/proxmox-compression/src/zip.rs
index e67613e4..d7bdd296 100644
--- a/proxmox-compression/src/zip.rs
+++ b/proxmox-compression/src/zip.rs
@@ -17,7 +17,7 @@ use std::time::SystemTime;
 use anyhow::{format_err, Error, Result};
 use endian_trait::Endian;
 use futures::ready;
-use libc::{S_IFDIR, S_IFREG};
+use libc::{S_IFDIR, S_IFLNK, S_IFREG};
 use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf};
 
 use crc32fast::Hasher;
@@ -76,6 +76,7 @@ fn epoch_to_dos(epoch: i64) -> (u16, u16) {
 pub enum FileType {
     Directory,
     Regular,
+    Symlink,
 }
 
 #[derive(Endian)]
@@ -236,6 +237,7 @@ impl ZipEntry {
         mode |= match file_type {
             FileType::Regular => S_IFREG,
             FileType::Directory => S_IFDIR,
+            FileType::Symlink => S_IFLNK,
         } as u16;
 
         Self {
@@ -656,7 +658,8 @@ where
         let encoder = &mut encoder;
 
         let entry = async move {
-            let entry_path_no_base = entry.path().strip_prefix(base_path)?;
+            let entrypath = entry.path();
+            let entry_path_no_base = entrypath.strip_prefix(base_path)?;
             let metadata = entry.metadata()?;
             let mtime = match metadata
                 .modified()
@@ -669,13 +672,18 @@ where
             let mode = metadata.mode() as u16;
 
             if entry.file_type().is_file() {
-                let file = tokio::fs::File::open(entry.path()).await?;
+                let file = Box::new(tokio::fs::File::open(entrypath).await?);
                 let ze = ZipEntry::new(entry_path_no_base, mtime, mode, FileType::Regular);
-                Ok(Some((ze, Some(file))))
+                Ok(Some((ze, Some::<Box<dyn AsyncRead + Send + Unpin>>(file))))
             } else if entry.file_type().is_dir() {
                 let ze = ZipEntry::new(entry_path_no_base, mtime, mode, FileType::Directory);
-                let content: Option<tokio::fs::File> = None;
-                Ok(Some((ze, content)))
+                Ok(Some((ze, None)))
+            } else if entry.file_type().is_symlink() {
+                let target: Box<dyn AsyncRead + Send + Unpin> = Box::new(io::Cursor::new(
+                    entrypath.read_link()?.into_os_string().into_encoded_bytes(),
+                ));
+                let ze = ZipEntry::new(entry_path_no_base, mtime, mode, FileType::Symlink);
+                Ok(Some((ze, Some(target))))
             } else {
                 // ignore other file types
                 Ok::<_, Error>(None)
-- 
2.47.3



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  parent reply	other threads:[~2025-10-27 13:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27 13:24 [pbs-devel] [PATCH proxmox{, -backup} v5 0/5] fix #4995: include symlinks in zip file restore Filip Schauer
2025-10-27 13:24 ` [pbs-devel] [PATCH proxmox v5 1/5] compression: zip: add a FileType enum Filip Schauer
2025-10-27 13:24 ` Filip Schauer [this message]
2025-10-27 13:24 ` [pbs-devel] [PATCH proxmox v5 3/5] compression: add tests for the ZipEncoder Filip Schauer
2025-10-27 13:24 ` [pbs-devel] [PATCH proxmox-backup v5 4/5] pxar: Adopt FileType enum when adding a zip entry Filip Schauer
2025-10-27 13:24 ` [pbs-devel] [PATCH proxmox-backup v5 5/5] 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=20251027132450.101103-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal