Browse Source

Avoid filesystem snapshot related race condition with mtimes

Jonas Borgström 13 years ago
parent
commit
9d508c9d18
1 changed files with 6 additions and 1 deletions
  1. 6 1
      darc/cache.py

+ 6 - 1
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)