浏览代码

fix crash when upgrading erroneous hints file, fixes #4922

if an old hints file gets converted to the new format and it
has entries referring to non-existent segment files, a crash
occurred.

with this code, the crash is avoided and the erroneous hints
entry is removed.
Thomas Waldmann 5 年之前
父节点
当前提交
2211aaab48
共有 1 个文件被更改,包括 11 次插入2 次删除
  1. 11 2
      src/borg/repository.py

+ 11 - 2
src/borg/repository.py

@@ -894,10 +894,19 @@ class Repository:
 
     def _rebuild_sparse(self, segment):
         """Rebuild sparse bytes count for a single segment relative to the current index."""
-        self.compact[segment] = 0
+        try:
+            segment_size = self.io.segment_size(segment)
+        except FileNotFoundError:
+            # segment does not exist any more, remove it from the mappings
+            # note: no need to self.compact.pop(segment), as we start from empty mapping.
+            self.segments.pop(segment)
+            return
+
         if self.segments[segment] == 0:
-            self.compact[segment] += self.io.segment_size(segment)
+            self.compact[segment] = segment_size
             return
+
+        self.compact[segment] = 0
         for tag, key, offset, size in self.io.iter_objects(segment, read_data=False):
             if tag == TAG_PUT:
                 if self.index.get(key, (-1, -1)) != (segment, offset):