From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Tue, 22 May 2007 21:04:16 +0000 (-0700)
Subject: don't test for existence of certfile and then try to open it -- instead try to open... 
X-Git-Tag: allmydata-tahoe-0.3.0~70
X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/module-simplejson.html?a=commitdiff_plain;h=98066ccaee22477e72fc330143da715412e2227f;p=tahoe-lafs%2Ftahoe-lafs.git

don't test for existence of certfile and then try to open it -- instead try to open it and catch exception
This avoids a race condition, also known as time-of-check-to-time-of-use.
---

diff --git a/src/allmydata/node.py b/src/allmydata/node.py
index c0c89159..2611fddf 100644
--- a/src/allmydata/node.py
+++ b/src/allmydata/node.py
@@ -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())