]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
don't test for existence of certfile and then try to open it -- instead try to open...
authorZooko O'Whielacronx <zooko@zooko.com>
Tue, 22 May 2007 21:04:16 +0000 (14:04 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Tue, 22 May 2007 21:04:16 +0000 (14:04 -0700)
This avoids a race condition, also known as time-of-check-to-time-of-use.

src/allmydata/node.py

index c0c89159128438fc01a130e827b506a6435b80e7..2611fddf8a887f9648b3974a7df486d0a97b778d 100644 (file)
@@ -31,11 +31,11 @@ class Node(service.MultiService):
         self._tub_ready_observerlist = observer.OneShotObserverList()
         assert self.CERTFILE, "Your node.Node subclass must provide CERTFILE"
         certfile = os.path.join(self.basedir, self.CERTFILE)
-        if os.path.exists(certfile):
+        try:
             f = open(certfile, "rb")
             self.tub = Tub(certData=f.read())
             f.close()
-        else:
+        except EnvironmentError:
             self.tub = Tub()
             f = open(certfile, "wb")
             f.write(self.tub.getCertData())