[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Bugfix: As of Python 2.3 (and maybe 2.2), the old patte...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv27403/lib/mixminion

Modified Files:
	Filestore.py 
Log Message:
Bugfix: As of Python 2.3 (and maybe 2.2), the old pattern for forcing
every database object to have a .sync() method will no longer work.
This got us onto trouble with dbm objects.  This patch no longer tries
to add new methods onto less featureful databases, but instead wraps
the whole thing in another layer of indirection.



Index: Filestore.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Filestore.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- Filestore.py	28 Aug 2003 18:43:44 -0000	1.9
+++ Filestore.py	19 Sep 2003 04:06:04 -0000	1.10
@@ -533,6 +533,7 @@
     #       database implementations (such as dumdbm) create multiple files,
     #       using <filename> as a prefix.
     # log -- The underlying anydbm object.
+    # _syncLog -- no-arguments function to flush self.log to disk.
     def __init__(self, filename, purpose=""):
         """Create a DBBase object for a database stored in 'filename',
            creating the underlying database if needed."""
@@ -555,14 +556,15 @@
 
         LOG.debug("Opening %s database at %s", purpose, filename)
         self.log = anydbm.open(filename, 'c')
-        if not hasattr(self.log, 'sync'):
-            if hasattr(self.log, '_commit'):
-                # Workaround for dumbdbm to allow syncing. (Standard in 
-                # Python 2.3.)
-                self.log.sync = self.log._commit
-            else:
-                # Otherwise, force a no-op sync method.
-                self.log.sync = lambda : None
+        if hasattr(self.log, 'sync'):
+            self._syncLog = self.log.sync
+        elif hasattr(self.log, '_commit'):
+            # Workaround for dumbdbm to allow syncing. (Standard in 
+            # Python 2.3.)
+            self._syncLog = self.log._commit
+        else:
+            # Otherwise, force a no-op sync method.
+            self._syncLog = lambda : None
 
         if isinstance(self.log, dumbdbm._Database):
             LOG.warn("Warning: using a flat file for %s database", purpose)
@@ -633,7 +635,7 @@
         """Flush all pending changes to disk"""
         self._lock.acquire()
         try:
-            self.log.sync()
+            self._syncLog()
         finally:
             self._lock.release()
 
@@ -758,7 +760,7 @@
                 ek = self._encodeKey(self._jDecodeKey(jk))
                 ev = self._encodeVal(self._jDecodeVal(self.journal[jk]))
                 self.log[ek] = ev
-            self.log.sync()
+            self._syncLog()
             os.close(self.journalFile)
             self.journalFile = os.open(self.journalFileName,
                                        _JOURNAL_OPEN_FLAGS|os.O_TRUNC, 0600)