[pbs-devel] [PATCH proxmox-backup 1/5] garbage collect: improve index error messages

Dominik Csapak d.csapak at proxmox.com
Mon Nov 2 12:34:35 CET 2020


so that in case of a broken index file, the user knows which it is

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/backup/datastore.rs | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/backup/datastore.rs b/src/backup/datastore.rs
index 94d0cc04..36ff32c8 100644
--- a/src/backup/datastore.rs
+++ b/src/backup/datastore.rs
@@ -475,10 +475,22 @@ impl DataStore {
                 Ok(file) => {
                     if let Ok(archive_type) = archive_type(&path) {
                         if archive_type == ArchiveType::FixedIndex {
-                            let index = FixedIndexReader::new(file)?;
+                            let index = FixedIndexReader::new(file).map_err(|err| {
+                                    format_err!(
+                                        "cannot read fixed index {}: {}",
+                                        full_path.to_string_lossy(),
+                                        err
+                                    )
+                            })?;
                             self.index_mark_used_chunks(index, &path, status, worker)?;
                         } else if archive_type == ArchiveType::DynamicIndex {
-                            let index = DynamicIndexReader::new(file)?;
+                            let index = DynamicIndexReader::new(file).map_err(|err| {
+                                    format_err!(
+                                        "cannot read dynamic index {}: {}",
+                                        full_path.to_string_lossy(),
+                                        err
+                                    )
+                            })?;
                             self.index_mark_used_chunks(index, &path, status, worker)?;
                         }
                     }
@@ -487,7 +499,11 @@ impl DataStore {
                     if err.kind() == std::io::ErrorKind::NotFound {
                         // simply ignore vanished files
                     } else {
-                        return Err(err.into());
+                        return Err(format_err!(
+                            "cannot open index {}: {}",
+                            full_path.to_string_lossy(),
+                            err
+                        ));
                     }
                 }
             }
-- 
2.20.1






More information about the pbs-devel mailing list