From 9d508c9d18235009a590f981366f91ded7a35bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Thu, 1 Mar 2012 22:35:11 +0100 Subject: [PATCH] Avoid filesystem snapshot related race condition with mtimes --- darc/cache.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/darc/cache.py b/darc/cache.py index 18d013373..10ac0338b 100644 --- a/darc/cache.py +++ b/darc/cache.py @@ -60,6 +60,7 @@ class Cache(object): def _read_files(self): self.files = {} + self._newest_mtime = 0 with open(os.path.join(self.path, 'files'), 'rb') as fd: u = msgpack.Unpacker() while True: @@ -90,7 +91,10 @@ class Cache(object): if self.files is not None: with open(os.path.join(self.path, 'files'), 'wb') as fd: for item in self.files.iteritems(): - msgpack.pack(item, fd) + # Discard cached files with the newest mtime to avoid + # issues with filesystem snapshots and mtime precision + if item[1][3] < self._newest_mtime: + msgpack.pack(item, fd) self.config.set('cache', 'manifest', self.manifest.id.encode('hex')) with open(os.path.join(self.path, 'config'), 'w') as fd: self.config.write(fd) @@ -206,4 +210,5 @@ class Cache(object): def memorize_file(self, path_hash, st, ids): # Entry: Age, inode, size, mtime, chunk ids self.files[path_hash] = 0, st.st_ino, st.st_size, st.st_mtime, ids + self._newest_mtime = max(self._newest_mtime, st.st_mtime)