From 71229138255e9c3541efd83b89bbec960944b9d6 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 6 Sep 2017 05:42:22 +0200 Subject: [PATCH] repo cleanup/write: invalidate cached FDs --- src/borg/repository.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/borg/repository.py b/src/borg/repository.py index ca55c6988..dada3c14e 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -1176,6 +1176,8 @@ class LoggedIO: count = 0 for segment, filename in self.segment_iterator(reverse=True): if segment > transaction_id: + if segment in self.fds: + del self.fds[segment] truncate_and_unlink(filename) count += 1 else: @@ -1232,6 +1234,12 @@ class LoggedIO: self._write_fd = SyncFile(self.segment_filename(self.segment), binary=True) self._write_fd.write(MAGIC) self.offset = MAGIC_LEN + if self.segment in self.fds: + # we may have a cached fd for a segment file we already deleted and + # we are writing now a new segment file to same file name. get rid of + # of the cached fd that still refers to the old file, so it will later + # get repopulated (on demand) with a fd that refers to the new file. + del self.fds[self.segment] return self._write_fd def get_fd(self, segment):