From 2a8cacf517b361f032a92090182dac39f0a6772f Mon Sep 17 00:00:00 2001 From: Rayyan Ansari Date: Thu, 10 Nov 2022 17:59:16 +0000 Subject: [PATCH] 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 --- src/borg/repository.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/borg/repository.py b/src/borg/repository.py index a8cb91d9c..247d9db1e 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -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