changeset 5048:149357d4bb4d

fix locking for CacheEntry (wrong 'finally:')
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 29 Aug 2009 01:46:14 +0200
parents ae8bf4c7d5a1
children 708fc89b4ebc
files MoinMoin/caching.py
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/caching.py	Wed Aug 26 13:59:33 2009 +0200
+++ b/MoinMoin/caching.py	Sat Aug 29 01:46:14 2009 +0200
@@ -168,21 +168,28 @@
         if not self.locking or self.locking and self._lock.acquire(1.0):
             try:
                 if 'r' in mode:
-                    self._fileobj = open(self._fname, mode, bufsize)
+                    filename = self._fname
+                    self._fileobj = open(filename, mode, bufsize)
                 elif 'w' in mode:
                     # we do not write content to old inode, but to a new file
                     # so we don't need to lock when we just want to read the file
                     # (at least on POSIX, this works)
-                    fd, self._tmp_fname = tempfile.mkstemp('.tmp', self.key, self.arena_dir)
+                    filename = None
+                    fd, filename = tempfile.mkstemp('.tmp', self.key, self.arena_dir)
+                    self._tmp_fname = filename
                     self._fileobj = os.fdopen(fd, mode, bufsize)
                 else:
                     raise ValueError("caching: mode does not contain 'r' or 'w'")
-            finally:
+            except IOError, err:
                 if self.locking:
                     self._lock.release()
                     self._lock = None
+                logging.error("Can't open cache file %s [%s]" % (filename, str(err))
+                raise CacheError(str(err))
         else:
-            logging.error("Can't acquire read/write lock in %s" % self.lock_dir)
+            err = "Can't acquire read/write lock in %s" % self.lock_dir
+            logging.error(err)
+            raise CacheError(err)
 
 
     def read(self, size=-1):