This avoids a race condition, also known as time-of-check-to-time-of-use.
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())