From b96bc155ac49a947da810c2b9c6a8a6e88af53b6 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 4 Aug 2016 00:06:15 +0200 Subject: [PATCH] fix unintended file cache eviction, fixes #1430 thanks much to e477 for diagnosing this and finding the right fix. --- borg/cache.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/borg/cache.py b/borg/cache.py index 29d0c8a14..7badac505 100644 --- a/borg/cache.py +++ b/borg/cache.py @@ -196,10 +196,13 @@ Chunk index: {0.total_unique_chunks:20d} {0.total_chunks:20d}""" ttl = int(os.environ.get('BORG_FILES_CACHE_TTL', 20)) with open(os.path.join(self.path, 'files'), 'wb') as fd: for path_hash, item in self.files.items(): - # Discard cached files with the newest mtime to avoid - # issues with filesystem snapshots and mtime precision + # Only keep files seen in this backup that are older than newest mtime seen in this backup - + # this is to avoid issues with filesystem snapshots and mtime granularity. + # Also keep files from older backups that have not reached BORG_FILES_CACHE_TTL yet. item = msgpack.unpackb(item) - if item[0] < ttl and bigint_to_int(item[3]) < self._newest_mtime: + age = item[0] + if age == 0 and bigint_to_int(item[3]) < self._newest_mtime or \ + age > 0 and age < ttl: msgpack.pack((path_hash, item), fd) self.config.set('cache', 'manifest', hexlify(self.manifest.id).decode('ascii')) self.config.set('cache', 'timestamp', self.manifest.timestamp)