Browse Source

Fix issue with truncated file cache file

Jonas Borgström 14 years ago
parent
commit
1711a457f7
1 changed files with 6 additions and 5 deletions
  1. 6 5
      darc/cache.py

+ 6 - 5
darc/cache.py

@@ -60,7 +60,7 @@ class Cache(object):
         self.id = self.config.get('cache', 'store_id').decode('hex')
         self.tid = self.config.getint('cache', 'tid')
         self.chunks = NSIndex(os.path.join(self.path, 'chunks'))
-        self.files = {}
+        self.files = None
 
     def _read_files(self):
         with open(os.path.join(self.path, 'files'), 'rb') as fd:
@@ -90,9 +90,10 @@ class Cache(object):
         """
         if not self.txn_active:
             return
-        with open(os.path.join(self.path, 'files'), 'wb') as fd:
-            for item in self.files.iteritems():
-                msgpack.pack(item, fd)
+        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)
         for id, (count, size) in self.chunks.iteritems():
             if count > 1000000:
                 self.chunks[id] = count - 1000000, size
@@ -170,7 +171,7 @@ class Cache(object):
             self.chunks[id] = (count - 1, size)
 
     def file_known_and_unchanged(self, path_hash, st):
-        if not self.files:
+        if self.files is None:
             self._read_files()
         entry = self.files.get(path_hash)
         if (entry and entry[3] == st.st_mtime