Skip to content

Commit 4a0b71c

Browse files
legacyrepository: remove auto_recover, see #9022
we only read from borg 1.x legacy repos, we must not try to "fix" them (users can use borg1 check --repair). had to remove some tests that relied on this "feature".
1 parent d955f8c commit 4a0b71c

File tree

2 files changed

+5
-39
lines changed

2 files changed

+5
-39
lines changed

src/borg/legacyrepository.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -515,23 +515,13 @@ def _read_integrity(self, transaction_id, key):
515515
return
516516
return integrity[key]
517517

518-
def open_index(self, transaction_id, auto_recover=True):
518+
def open_index(self, transaction_id):
519519
if transaction_id is None:
520520
return NSIndex1()
521521
index_path = os.path.join(self.path, "index.%d" % transaction_id)
522522
integrity_data = self._read_integrity(transaction_id, "index")
523-
try:
524-
with IntegrityCheckedFile(index_path, write=False, integrity_data=integrity_data) as fd:
525-
return NSIndex1.read(fd)
526-
except (ValueError, OSError, FileIntegrityError) as exc:
527-
logger.warning("Repository index missing or corrupted, trying to recover from: %s", exc)
528-
os.unlink(index_path)
529-
if not auto_recover:
530-
raise
531-
self.prepare_txn(self.get_transaction_id())
532-
# don't leave an open transaction around
533-
self.commit(compact=False)
534-
return self.open_index(self.get_transaction_id())
523+
with IntegrityCheckedFile(index_path, write=False, integrity_data=integrity_data) as fd:
524+
return NSIndex1.read(fd)
535525

536526
def _unpack_hints(self, transaction_id):
537527
hints_path = os.path.join(self.path, "hints.%d" % transaction_id)
@@ -560,11 +550,11 @@ def prepare_txn(self, transaction_id, do_cleanup=True):
560550
raise
561551
if not self.index or transaction_id is None:
562552
try:
563-
self.index = self.open_index(transaction_id, auto_recover=False)
553+
self.index = self.open_index(transaction_id)
564554
except (ValueError, OSError, FileIntegrityError) as exc:
565555
logger.warning("Checking repository transaction due to previous error: %s", exc)
566556
self.check_transaction()
567-
self.index = self.open_index(transaction_id, auto_recover=False)
557+
self.index = self.open_index(transaction_id)
568558
if transaction_id is None:
569559
self.segments = {} # XXX bad name: usage_count_of_segment_x = self.segments[x]
570560
self.compact = FreeSpace() # XXX bad name: freeable_space_of_segment_x = self.compact[x]

src/borg/testsuite/legacyrepository_test.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -571,21 +571,6 @@ def test_unreadable_hints(repository):
571571
do_commit(repository)
572572

573573

574-
def test_index(repository):
575-
make_auxiliary(repository)
576-
with open(os.path.join(repository.path, "index.1"), "wb") as fd:
577-
fd.write(b"123456789")
578-
do_commit(repository)
579-
580-
581-
def test_index_outside_transaction(repository):
582-
make_auxiliary(repository)
583-
with open(os.path.join(repository.path, "index.1"), "wb") as fd:
584-
fd.write(b"123456789")
585-
with repository:
586-
assert len(repository) == 1
587-
588-
589574
def _corrupt_index(repository):
590575
# HashIndex is able to detect incorrect headers and file lengths,
591576
# but on its own it can't tell if the data is correct.
@@ -601,15 +586,6 @@ def _corrupt_index(repository):
601586
fd.write(corrupted_index_data)
602587

603588

604-
def test_index_corrupted(repository):
605-
make_auxiliary(repository)
606-
_corrupt_index(repository)
607-
with repository:
608-
# data corruption is detected due to mismatching checksums, and fixed by rebuilding the index.
609-
assert len(repository) == 1
610-
assert pdchunk(repository.get(H(0))) == b"foo"
611-
612-
613589
def test_index_corrupted_without_integrity(repository):
614590
make_auxiliary(repository)
615591
_corrupt_index(repository)

0 commit comments

Comments
 (0)