public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] compression: zip_directory: improve error handling
Date: Wed, 10 May 2023 15:22:58 +0200	[thread overview]
Message-ID: <20230510132258.3350401-1-d.csapak@proxmox.com> (raw)

when zipping a directory, our intention was to skip over files that
cannot be zipped (e.g. the file can't be read/vanished/etc.), so we
ignored errors and simply logged it.

but when 'add_entry' fails, we will never actually restore, since every
error there is fatal to the point that the zip cannot be finished thats
because we take the 'target' sink out of self, and only insert it again
after all writes succeeded. so if an error occurs in between 'target' is
not put into self again (and never will be) and the zip cannot be
finished (even if we would catch all those intermediate errors and
restore 'target', we don't know in which state the output was, so we're
unable to finish a valid zip)

to fix that, split the actual 'add_entry' part there out of the async
move block and treat its errors always as fatal

without this, we generate heaps of log lines even after an error
occurred, and can never recover

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
note that i know we use 'eprintln' instead of the log macro, but it's
not part of the fix, and i don't know if we want to add the log crate as
dep here. we only use this function currently in the restore daemon for
downloading a directory

 proxmox-compression/src/zip.rs | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/proxmox-compression/src/zip.rs b/proxmox-compression/src/zip.rs
index c9ed80e..6d457fb 100644
--- a/proxmox-compression/src/zip.rs
+++ b/proxmox-compression/src/zip.rs
@@ -643,7 +643,7 @@ where
         let entry_path = entry.path().to_owned();
         let encoder = &mut encoder;
 
-        if let Err(err) = async move {
+        match async move {
             let entry_path_no_base = entry.path().strip_prefix(base_path)?;
             let metadata = entry.metadata()?;
             let mtime = match metadata
@@ -659,22 +659,27 @@ 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);
-                encoder.add_entry(ze, Some(file)).await?;
+                Ok(Some((ze, Some(file))))
             } else if entry.file_type().is_dir() {
                 let ze = ZipEntry::new(entry_path_no_base, mtime, mode, false);
                 let content: Option<tokio::fs::File> = None;
-                encoder.add_entry(ze, content).await?;
+                Ok(Some((ze, content)))
+            } else {
+                // ignore other file types
+                Ok::<_, Error>(None)
             }
-            // ignore other file types
-            Ok::<(), Error>(())
         }
         .await
         {
-            eprintln!(
-                "zip: error encoding file or directory '{}': {}",
-                entry_path.display(),
-                err
-            );
+            Ok(Some((ze, content))) => encoder.add_entry(ze, content).await?,
+            Ok(None) => {}
+            Err(err) => {
+                eprintln!(
+                    "zip: error encoding file or directory '{}': {}",
+                    entry_path.display(),
+                    err
+                );
+            }
         }
     }
 
-- 
2.30.2





             reply	other threads:[~2023-05-10 13:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10 13:22 Dominik Csapak [this message]
2023-06-14  9:58 ` Dominik Csapak
2023-06-15  8:38   ` [pbs-devel] applied: " Wolfgang Bumiller

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=20230510132258.3350401-1-d.csapak@proxmox.com \
    --to=d.csapak@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