summaryrefslogtreecommitdiff
path: root/sphinx/application.py
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-12-07 23:15:05 +0100
committerMichał Górny <mgorny@gentoo.org>2017-12-16 09:50:09 +0100
commit14af6b429ef2355ba0e8342c4af0f9dd9aafab1d (patch)
tree388174d42a31ab43af04e472430666ad78bb5ced /sphinx/application.py
parent7cabd6cbb053965e1930b53c27d596fd1a52dd78 (diff)
downloadsphinx-git-14af6b429ef2355ba0e8342c4af0f9dd9aafab1d.tar.gz
Use ensuredir() instead of os.makedirs() to fix race conditions
Use the ensuredir() function consistently across Sphinx code to avoid race conditions e.g. when multiple Sphinx instances attempt to create the same output directory. The ensuredir() function that was already present in sphinx.util.osutil correctly catches EEXIST exception that occurs if the specified directory already exists (i.e. it was created between the call to os.path.isdir() and os.makedirs() that follows it). While at it, remove redundant os.path.isdir() calls when they only guarded the os.makedirs() call, and replace mkdir_p() which had pretty much the same purpose, except for being prone to race conditions. I did not modify testing-related code as race conditions mostly affect real applications and not the test environment. Fix #4281: Race conditions when creating output directory
Diffstat (limited to 'sphinx/application.py')
-rw-r--r--sphinx/application.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/sphinx/application.py b/sphinx/application.py
index 0d6d3d0b3..b5705face 100644
--- a/sphinx/application.py
+++ b/sphinx/application.py
@@ -41,7 +41,7 @@ from sphinx.util import import_object
from sphinx.util import logging
from sphinx.util import status_iterator, old_status_iterator, display_chunk
from sphinx.util.tags import Tags
-from sphinx.util.osutil import ENOENT
+from sphinx.util.osutil import ENOENT, ensuredir
from sphinx.util.console import bold, darkgreen # type: ignore
from sphinx.util.docutils import is_html5_writer_available, directive_helper
from sphinx.util.i18n import find_catalog_source_files
@@ -160,7 +160,7 @@ class Sphinx(object):
if not path.isdir(outdir):
logger.info('making output directory...')
- os.makedirs(outdir)
+ ensuredir(outdir)
# read config
self.tags = Tags(tags)