[Zope-CVS] CVS: Products/FileCacheManager - FileCacheManager.py:1.13

Jens Vagelpohl jens at dataflake.org
Mon Aug 16 04:11:45 EDT 2004


Update of /cvs-repository/Products/FileCacheManager
In directory cvs.zope.org:/tmp/cvs-serv28565

Modified Files:
	FileCacheManager.py 
Log Message:
- add locks around the place where cache files are written and deleted.
  The simple unit tests can't really test for that yet.


=== Products/FileCacheManager/FileCacheManager.py 1.12 => 1.13 ===
--- Products/FileCacheManager/FileCacheManager.py:1.12	Sun Aug 15 12:34:45 2004
+++ Products/FileCacheManager/FileCacheManager.py	Mon Aug 16 04:11:44 2004
@@ -102,18 +102,21 @@
 
     def ZCache_invalidate(self, ob):
         """ Invalidate cache entries that apply to ob """
-        # XXX ADD LOCKS HERE
         fname = self._fileName(ob)
 
         try:
-            if os.path.exists(fname): # XXX race?
-                os.remove(fname)
-        except IOError, msg:
-             zLOG.LOG( 'FileCacheManager'
-                     , zLOG.ERROR
-                     , 'IOError removing file'
-                     , error=msg
-                     )
+            try:
+                self.writelock.acquire()
+                if os.path.exists(fname): # XXX race?
+                    os.remove(fname)
+            except IOError, msg:
+                 zLOG.LOG( 'FileCacheManager'
+                         , zLOG.ERROR
+                         , 'IOError removing file'
+                         , error=msg
+                         )
+        finally:
+            self.writelock.release()
 
     def ZCache_get(self, ob, view_name='', keywords=None,
                    mtime_func=None, default=None):
@@ -135,7 +138,6 @@
     def ZCache_set(self, ob, data=None, view_name='', keywords=None,
                    mtime_func=None):
         """ Sets a cache entry. """
-        # XXX locks?
         fname = self._fileName(ob)
 
         if data is None:
@@ -163,12 +165,16 @@
                 # rename that sucker.
                 # This may fail if they are not on the same filesystem.
                 try:
-                    os.rename(tempname, fname)
-                except OSError:
-                    # windows fails if fname exists.
-                    # if this doesn't work, tough noogies
-                    os.unlink(fname)
-                    os.rename(tempname, fname)
+                    self.writelock.acquire()
+                    try:
+                        os.rename(tempname, fname)
+                    except OSError:
+                        # windows fails if fname exists.
+                        # if this doesn't work, tough noogies
+                        os.unlink(fname)
+                        os.rename(tempname, fname)
+                finally:
+                    self.writelock.release()
 
         except IOError, msg:
             LOG('FileCacheManager', ERROR, 'IOError writing file', error=msg)



More information about the Zope-CVS mailing list