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

[minion-cvs] More key rotation fixes: joy



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

Modified Files:
	HashLog.py 
Log Message:
More key rotation fixes: joy

Index: HashLog.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/HashLog.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- HashLog.py	30 May 2003 13:54:45 -0000	1.11
+++ HashLog.py	30 May 2003 14:02:05 -0000	1.12
@@ -24,17 +24,22 @@
 # We flush the log every MAX_JOURNAL hashes.
 MAX_JOURNAL = 128
 
+_HASHLOG_DICT_LOCK = threading.Lock()
+
 #DOCDOC
 _OPEN_HASHLOGS = {}
 
-#XXXX004 locking??
 def getHashLog(filename, keyid):
     try:
-        return _OPEN_HASHLOGS[(filename, keyid)]
-    except KeyError:
-        hl = HashLog(filename, keyid)
-        _OPEN_HASHLOGS[(filename, keyid)] = hl
-        return hl
+        _HASHLOG_DICT_LOCK.acquire()
+        try:
+            return _OPEN_HASHLOGS[(filename, keyid)]
+        except KeyError:
+            hl = HashLog(filename, keyid)
+            _OPEN_HASHLOGS[(filename, keyid)] = hl
+            return hl
+    finally:
+        _HASHLOG_DICT_LOCK.release()
 
 # flags to pass to os.open when opening the journal file.
 _JOURNAL_OPEN_FLAGS = os.O_WRONLY|os.O_CREAT|getattr(os,'O_SYNC',0)
@@ -74,6 +79,8 @@
     def __init__(self, filename, keyid):
         """Create a new HashLog to store data in 'filename' for the key
            'keyid'."""
+        self.filename = filename
+        self.keyid = keyid
         parent = os.path.split(filename)[0]
         createPrivateDir(parent)
 
@@ -170,5 +177,14 @@
             self.sync()
             self.log.close()
             os.close(self.journalFile)
+            try:
+                _HASHLOG_DICT_LOCK.acquire()
+                try:
+                    del _OPEN_HASHLOGS[(self.filename, self.keyid)]
+                except KeyError:
+                    pass
+            finally:
+                _HASHLOG_DICT_LOCK.release()
+                    
         finally:
             self.__lock.release()