Commit 342443f5 authored by Paul Ganssle's avatar Paul Ganssle

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.
parent bb36b418
......@@ -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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment