1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-03-01 09:17:02 +00:00

Merge pull request #7147 from ThomasWaldmann/fix-repository-tests-1.2

Fix repository tests 1.2
This commit is contained in:
TW 2022-11-19 17:06:07 +01:00 committed by GitHub
commit c233a964f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -127,6 +127,7 @@ def __init__(self, path, write, filename=None, override_fd=None, integrity_data=
self.writing = write
mode = 'wb' if write else 'rb'
self.file_fd = override_fd or open(path, mode)
self.file_opened = override_fd is None
self.digests = {}
hash_cls = XXH64FileHashingWrapper
@ -189,9 +190,13 @@ def hash_part(self, partname, is_final=False):
def __exit__(self, exc_type, exc_val, exc_tb):
exception = exc_type is not None
if not exception:
self.hash_part('final', is_final=True)
self.hasher.__exit__(exc_type, exc_val, exc_tb)
try:
if not exception:
self.hash_part("final", is_final=True)
self.hasher.__exit__(exc_type, exc_val, exc_tb)
finally:
if self.file_opened:
self.file_fd.close()
if exception:
return
if self.writing:

View file

@ -613,7 +613,7 @@ def flush_and_sync(fd):
os.fsync(fd.fileno())
def rename_tmp(file):
os.rename(file + '.tmp', file)
os.replace(file + ".tmp", file)
hints = {
b'version': 2,
@ -1358,13 +1358,12 @@ def get_segments_transaction_id(self):
def cleanup(self, transaction_id):
"""Delete segment files left by aborted transactions
"""
self.close_segment()
self.segment = transaction_id + 1
count = 0
for segment, filename in self.segment_iterator(reverse=True):
if segment > transaction_id:
if segment in self.fds:
del self.fds[segment]
safe_unlink(filename)
self.delete_segment(segment)
count += 1
else:
break

View file

@ -720,7 +720,7 @@ def corrupt_object(self, id_):
fd.write(b'BOOM')
def delete_segment(self, segment):
os.unlink(os.path.join(self.tmppath, 'repository', 'data', '0', str(segment)))
self.repository.io.delete_segment(segment)
def delete_index(self):
os.unlink(os.path.join(self.tmppath, 'repository', f'index.{self.get_head()}'))
@ -1002,6 +1002,14 @@ def test_crash_before_compact(self):
# skip this test, we can't mock-patch a Repository class in another process!
pass
def test_repair_missing_commit_segment(self):
# skip this test, files in RemoteRepository cannot be deleted
pass
def test_repair_missing_segment(self):
# skip this test, files in RemoteRepository cannot be deleted
pass
class RemoteLoggerTestCase(BaseTestCase):
def setUp(self):