builder.py: fix potential race condition

There is a possible TOCTOU race condition in the event that two
jenkins-jobs instances are running at the same time and try to create
the cache directory at the same time.

story: 2000374
Change-Id: Ie194eb7b52237356e8ab935aed97af577a96605b
This commit is contained in:
Jonathan Lebon 2015-10-08 11:58:23 -04:00
parent 3f0ff2dff6
commit 641eb75b69

@ -65,7 +65,14 @@ class CacheStorage(object):
os.path.join(home, '.cache')
path = os.path.join(xdg_cache_home, 'jenkins_jobs')
if not os.path.isdir(path):
os.makedirs(path)
try:
os.makedirs(path)
except OSError as ose:
# it could happen that two jjb instances are running at the
# same time and that the other instance created the directory
# after we made the check, in which case there is no error
if ose.errno != errno.EEXIST:
raise ose
return path
def set(self, job, md5):