Browse Source

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
Rayyan Ansari 2 years ago
parent
commit
2a8cacf517
1 changed files with 2 additions and 3 deletions
  1. 2 3
      src/borg/repository.py

+ 2 - 3
src/borg/repository.py

@@ -1448,13 +1448,12 @@ class LoggedIO:
 
     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