From 1711a457f719baa898f0d5b76cb5fef8e319c2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Wed, 6 Jul 2011 22:11:01 +0200 Subject: [PATCH] Fix issue with truncated file cache file --- darc/cache.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/darc/cache.py b/darc/cache.py index 58fbc1468..c1c3caf8c 100644 --- a/darc/cache.py +++ b/darc/cache.py @@ -60,7 +60,7 @@ def open(self): 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 @@ def commit(self): """ 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 @@ def chunk_decref(self, id): 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