summaryrefslogtreecommitdiffstats
path: root/jenkins_jobs/builder.py
diff options
context:
space:
mode:
authorJonathan Lebon <jlebon@redhat.com>2015-10-08 11:58:23 -0400
committerJonathan Lebon <jlebon@redhat.com>2015-10-08 12:49:07 -0400
commit641eb75b69eccd9d81280ff987dc3cfae3a7b4e0 (patch)
treef14446e2aa1652c85acfa398fe63053ce0d1e344 /jenkins_jobs/builder.py
parent3f0ff2dff6f60c5b9c098be0d03c64366e5b99d3 (diff)
downloadpython-jenkins-job-builder-641eb75b69eccd9d81280ff987dc3cfae3a7b4e0.tar.gz
python-jenkins-job-builder-641eb75b69eccd9d81280ff987dc3cfae3a7b4e0.tar.xz
python-jenkins-job-builder-641eb75b69eccd9d81280ff987dc3cfae3a7b4e0.zip
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
Diffstat (limited to 'jenkins_jobs/builder.py')
-rw-r--r--jenkins_jobs/builder.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py
index 060f2384..782fb975 100644
--- a/jenkins_jobs/builder.py
+++ b/jenkins_jobs/builder.py
@@ -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):