]> git.proxmox.com Git - proxmox-backup.git/commitdiff
datastore: list images: reduce indentation depth on error checking
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 8 Sep 2023 09:01:28 +0000 (11:01 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 8 Sep 2023 09:05:10 +0000 (11:05 +0200)
Simply pull out the inner IO error and the affected path first.

Clean up style-wise a bit while touching this anyway, but no semantic
change intended.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
pbs-datastore/src/datastore.rs

index fe75d9b5e3ea02644fe479fccf1ba139d7293610..d0c2b90a0b7611a481206e5e5ceb596e032fe750 100644 (file)
@@ -867,26 +867,22 @@ impl DataStore {
                 .unwrap_or(false)
         }
         let handle_entry_err = |err: walkdir::Error| {
-            if let Some(inner) = err.io_error() {
-                if let Some(path) = err.path() {
-                    if inner.kind() == io::ErrorKind::PermissionDenied {
-                        // only allow to skip ext4 fsck directory, avoid GC if, for example,
-                        // a user got file permissions wrong on datastore rsync to new server
-                        if err.depth() > 1 || !path.ends_with("lost+found") {
-                            bail!("cannot continue garbage-collection safely, permission denied on: {:?}", path)
-                        }
-                    } else {
-                        bail!(
-                            "unexpected error on datastore traversal: {} - {:?}",
-                            inner,
-                            path
-                        )
-                    }
-                } else {
-                    bail!("unexpected error on datastore traversal: {}", inner)
+            // first, extract the actual IO error and the affected path
+            let (inner, path) = match (err.io_error(), err.path()) {
+                (None, _) => return Ok(()), // not an IO-error
+                (Some(inner), Some(path)) => (inner, path),
+                (Some(inner), None) => bail!("unexpected error on datastore traversal: {inner}"),
+            };
+            if inner.kind() == io::ErrorKind::PermissionDenied {
+                if err.depth() == 0 && path.ends_with("lost+found") {
+                    // allow skipping ext4 fsck-directory on EPERM only, otherwise we might prune
+                    // too many chunks. E.g., if users messed up with owner/perms on a rsync
+                    return Ok(());
                 }
+                bail!("cannot continue garbage-collection safely, permission denied on: {path:?}");
+            } else {
+                bail!("unexpected error on datastore traversal: {inner} - {path:?}");
             }
-            Ok(())
         };
         for entry in walker.filter_entry(|e| !is_hidden(e)) {
             let path = match entry {