From ebbab77a8603b9549534301bbeebfb98b14611a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Sun, 14 Aug 2011 14:50:56 +0200 Subject: [PATCH] Fix cache rollback logic race condition --- darc/cache.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/darc/cache.py b/darc/cache.py index ee03d6012..7314f725c 100644 --- a/darc/cache.py +++ b/darc/cache.py @@ -69,7 +69,7 @@ def _read_files(self): break u.feed(data) for hash, item in u: - if item[0] < 8: + if item[0] < 10: self.files[hash] = (item[0] + 1,) + item[1:] def begin_txn(self): @@ -104,16 +104,16 @@ def commit(self): def rollback(self): """Roll back partial and aborted transactions """ - # Remove partial transaction - if os.path.exists(os.path.join(self.path, 'txn.tmp')): - shutil.rmtree(os.path.join(self.path, 'txn.tmp')) # Roll back active transaction txn_dir = os.path.join(self.path, 'txn.active') if os.path.exists(txn_dir): shutil.copy(os.path.join(txn_dir, 'config'), self.path) shutil.copy(os.path.join(txn_dir, 'chunks'), self.path) shutil.copy(os.path.join(txn_dir, 'files'), self.path) - shutil.rmtree(txn_dir) + os.rename(txn_dir, os.path.join(self.path, 'txn.tmp')) + # Remove partial transaction + if os.path.exists(os.path.join(self.path, 'txn.tmp')): + shutil.rmtree(os.path.join(self.path, 'txn.tmp')) self.txn_active = False def sync(self):