diff options
author | Paul Ganssle <paul@ganssle.io> | 2018-07-11 10:23:55 -0400 |
---|---|---|
committer | Paul Ganssle <paul@ganssle.io> | 2018-07-12 09:07:51 -0400 |
commit | 342443f5034851bbd55823f2c900d7ebabe1b306 (patch) | |
tree | 5e48757d0fa6a4ecafc3169449cb5b64012e6222 | |
parent | bb36b41818b99079372dbb55b272465820d58de3 (diff) | |
download | external_python_setuptools-342443f5034851bbd55823f2c900d7ebabe1b306.tar.gz external_python_setuptools-342443f5034851bbd55823f2c900d7ebabe1b306.tar.bz2 external_python_setuptools-342443f5034851bbd55823f2c900d7ebabe1b306.zip |
Fix race condition in _bypass_ensure_directory
This fixes a race condition in _bypass_ensure_directory where
two threads or processes may erroneously fail because they are
both creating the same directory. A more robust implementation
of this may involve exposing the un-wrapped os.makedirs.
Originally reported with proposed patch by @JonKohler in
github PR #1412. This patch came out of discussions on that
thread.
-rw-r--r-- | pkg_resources/__init__.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 67015408..4f42156d 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -47,6 +47,11 @@ except ImportError: # Python 3.2 compatibility import imp as _imp +try: + FileExistsError +except NameError: + FileExistsError = OSError + from pkg_resources.extern import six from pkg_resources.extern.six.moves import urllib, map, filter @@ -3030,7 +3035,10 @@ def _bypass_ensure_directory(path): dirname, filename = split(path) if dirname and filename and not isdir(dirname): _bypass_ensure_directory(dirname) - mkdir(dirname, 0o755) + try: + mkdir(dirname, 0o755) + except FileExistsError: + pass def split_sections(s): |