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

[minion-cvs] Backport python 2.3 dbm fix to maint branch



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

Modified Files:
      Tag: mixminion-v0-0-5-patches
	Filestore.py 
Log Message:
Backport python 2.3 dbm fix to maint branch

Index: Filestore.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Filestore.py,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -d -r1.9 -r1.9.2.1
--- Filestore.py	28 Aug 2003 18:43:44 -0000	1.9
+++ Filestore.py	19 Sep 2003 04:26:57 -0000	1.9.2.1
@@ -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)