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

[minion-cvs] Bugfixes for armoring, refactor to use readFile/WriteFi...



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

Modified Files:
	ServerInbox.py ServerList.py 
Log Message:
Bugfixes for armoring, refactor to use readFile/WriteFile wrappers.

Common:
- Add "tryUnlink" function to perform common unlink-this-file-if-you-can
  operation.
- Debug armorText and unarmorText.
- Document writeFile and readFile

Packet:
- Remove dead comment.

test: 
- Remove redundant readFile and writeFile
- Add tests for armorText and unarmorText.

ClientMain, Common, ServerInbox, ServerList, EventStats, HashLogs, Modules,
   ServerKeys, ServerMain, ServerQueue:
- Use writeFile, readFile, tryUnlink where possible.
- Avoid "except" without "raise" or sys.exc_info()
- Avoid "except OSError" without checking errno or displaying error.


Index: ServerInbox.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/directory/ServerInbox.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ServerInbox.py	28 May 2003 08:37:49 -0000	1.6
+++ ServerInbox.py	5 Jun 2003 05:24:23 -0000	1.7
@@ -12,7 +12,7 @@
 import os
 
 from mixminion.Common import LOG, MixError, MixFatalError, UIError, \
-     readPickled, writePickled,formatBase64
+     formatBase64, readPickled, tryUnlink, writePickled
 from mixminion.ServerInfo import ServerInfo
 
 from mixminion.directory.Directory import getIDFingerprint, MismatchedID
@@ -195,9 +195,7 @@
 
     def delPendingServers(self, fnames):
         for fname in fnames:
-            try:
-                os.unlink(os.path.join(self.incomingDir, fname))
-            except OSError:
+            if not tryUnlink(os.path.join(self.incomingDir, fname)):
                 LOG.warn("delPendingServers: no such server %s"%fname)
 
 class ServerQueuedException(Exception):

Index: ServerList.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/directory/ServerList.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ServerList.py	2 Jun 2003 20:55:23 -0000	1.28
+++ ServerList.py	5 Jun 2003 05:24:23 -0000	1.29
@@ -26,10 +26,9 @@
 from mixminion.Crypto import pk_decode_public_key, pk_encode_public_key, \
      pk_same_public_key
 from mixminion.Common import IntervalSet, LOG, MixError, MixFatalError, \
-     UIError, createPrivateDir, \
-     formatBase64, formatDate, formatFnameTime, formatTime, Lockfile, \
-     openUnique, \
-     previousMidnight, readPickled, readPossiblyGzippedFile, stringContains, \
+     UIError, createPrivateDir, formatBase64, formatDate, formatFnameTime, \
+     formatTime, Lockfile, openUnique, previousMidnight, readFile, \
+     readPickled, readPossiblyGzippedFile, stringContains, writeFile, \
      writePickled
 from mixminion.Config import ConfigError
 from mixminion.ServerInfo import ServerDirectory, ServerInfo, \
@@ -287,9 +286,8 @@
 
             contents = [ ]
             for _, _, fn in included:
-                f = open(os.path.join(self.serverDir, fn), 'r')
-                contents.append(f.read())
-                f.close()
+                txt = readFile(os.path.join(self.serverDir, fn))
+                contents.append(txt)
 
             goodServers = [n for n,_,_ in included if n not in badServers]
             g = {}
@@ -336,9 +334,9 @@
                     foundDigests[s['Server']['Digest']] = 1
                 assert foundDigests == includedDigests
 
-            f = open(os.path.join(self.baseDir, "directory"), 'w')
-            f.write(directory)
-            f.close()
+            writeFile(os.path.join(self.baseDir, "directory"),
+                      directory, 
+                      mode=0644)
 
             f, _ = openUnique(os.path.join(self.dirArchiveDir,
                                             "dir-"+formatFnameTime()))