Skip to content

Commit

Permalink
fix the repair mode
Browse files Browse the repository at this point in the history
if one used --last (or since shortly: gave an archive name), verify_chunks (old method name) was
not called because it requires all archives having been checked.

the problem was that also the final manifest.write() and repository.commit() was done in that method,
so all other repair work did not get committed in that case.

I moved these calls that to a separate finish() method.
  • Loading branch information
ThomasWaldmann committed Aug 9, 2015
1 parent 4f6c43b commit 80ee8b9
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ def __init__(self):

def check(self, repository, repair=False, archive=None, last=None):
self.report_progress('Starting archive consistency check...')
self.check_all = archive is None and last is None
self.repair = repair
self.repository = repository
self.init_chunks()
Expand All @@ -620,10 +621,8 @@ def check(self, repository, repair=False, archive=None, last=None):
else:
self.manifest, _ = Manifest.load(repository, key=self.key)
self.rebuild_refcounts(archive=archive, last=last)
if last is None and archive is None:
self.verify_chunks()
else:
self.report_progress('Orphaned objects check skipped (needs all archives checked)')
self.orphan_chunks_check()
self.finish()
if not self.error_found:
self.report_progress('Archive consistency check complete, no problems found.')
return self.repair or not self.error_found
Expand Down Expand Up @@ -803,16 +802,22 @@ def missing_chunk_detector(chunk_id):
add_reference(new_archive_id, len(data), len(cdata), cdata)
info[b'id'] = new_archive_id

def verify_chunks(self):
unused = set()
for id_, (count, size, csize) in self.chunks.iteritems():
if count == 0:
unused.add(id_)
orphaned = unused - self.possibly_superseded
if orphaned:
self.report_progress('{} orphaned objects found'.format(len(orphaned)), error=True)
def orphan_chunks_check(self):
if self.check_all:
unused = set()
for id_, (count, size, csize) in self.chunks.iteritems():
if count == 0:
unused.add(id_)
orphaned = unused - self.possibly_superseded
if orphaned:
self.report_progress('{} orphaned objects found'.format(len(orphaned)), error=True)
if self.repair:
for id_ in unused:
self.repository.delete(id_)
else:
self.report_progress('Orphaned objects check skipped (needs all archives checked)')

def finish(self):
if self.repair:
for id_ in unused:
self.repository.delete(id_)
self.manifest.write()
self.repository.commit()

0 comments on commit 80ee8b9

Please sign in to comment.