1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-23 16:26:29 +00:00

repository: cleanup(): close segment before unlinking

On Windows, trying to delete a file that is already open raises an exception.

Docs:
https://docs.python.org/3/library/os.html#os.remove
This commit is contained in:
Rayyan Ansari 2022-11-10 17:59:16 +00:00
parent 62341673c1
commit 2a8cacf517

View file

@ -1448,13 +1448,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