mirror of https://github.com/borgbackup/borg.git
fix "check" for repos that have incomplete chunks, fixes #364
added try/finally (the code in between was just indented, no other code changes) to make sure it sets self.index back to None, even if the code crashes e.g. due to an IntegrityError caused by an incomplete segment caused by a disk full condition. also, in prepare_txn, create an empty in-memory index if transaction_id is None, which is required by the Repository.check code to work correctly. If the index is not empty there, it will miscalculate segment usage (self.segments).
This commit is contained in:
parent
1f271821b8
commit
98f3b8d937
|
@ -175,7 +175,7 @@ class Repository:
|
|||
# the repository instance lives on - even if exceptions happened.
|
||||
self._active_txn = False
|
||||
raise
|
||||
if not self.index:
|
||||
if not self.index or transaction_id is None:
|
||||
self.index = self.open_index(transaction_id)
|
||||
if transaction_id is None:
|
||||
self.segments = {}
|
||||
|
@ -237,11 +237,13 @@ class Repository:
|
|||
|
||||
def replay_segments(self, index_transaction_id, segments_transaction_id):
|
||||
self.prepare_txn(index_transaction_id, do_cleanup=False)
|
||||
try:
|
||||
for segment, filename in self.io.segment_iterator():
|
||||
if index_transaction_id is not None and segment <= index_transaction_id:
|
||||
continue
|
||||
if segment > segments_transaction_id:
|
||||
break
|
||||
# code duplication below?? vvv (see similar code in check())
|
||||
self.segments[segment] = 0
|
||||
for tag, key, offset in self.io.iter_objects(segment):
|
||||
if tag == TAG_PUT:
|
||||
|
@ -268,6 +270,7 @@ class Repository:
|
|||
if self.segments[segment] == 0:
|
||||
self.compact.add(segment)
|
||||
self.write_index()
|
||||
finally:
|
||||
self.rollback()
|
||||
|
||||
def check(self, repair=False):
|
||||
|
@ -297,7 +300,7 @@ class Repository:
|
|||
if repair:
|
||||
self.io.cleanup(transaction_id)
|
||||
segments_transaction_id = self.io.get_segments_transaction_id()
|
||||
self.prepare_txn(None)
|
||||
self.prepare_txn(None) # self.index, self.compact, self.segments all empty now!
|
||||
for segment, filename in self.io.segment_iterator():
|
||||
if segment > transaction_id:
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue