From 98066ccaee22477e72fc330143da715412e2227f Mon Sep 17 00:00:00 2001 From: Zooko O'Whielacronx Date: Tue, 22 May 2007 14:04:16 -0700 Subject: [PATCH] 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. --- src/allmydata/node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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()) -- 2.45.2