10000 Merge pull request #5224 from tacaswell/mnt_mkdirs_race · matplotlib/matplotlib@b518616 · GitHub
[go: up one dir, main page]

Skip to content

Commit b518616

Browse files
committed
Merge pull request #5224 from tacaswell/mnt_mkdirs_race
FIX: subtle race condition in cbook.mkdirs
2 parents 72ecc9c + 151db47 commit b518616

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/matplotlib/cbook.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,19 +1012,16 @@ def mkdirs(newdir, mode=0o777):
10121012
> mkdir -p NEWDIR
10131013
> chmod MODE NEWDIR
10141014
"""
1015-
try:
1016-
if not os.path.exists(newdir):
1017-
parts = os.path.split(newdir)
1018-
for i in range(1, len(parts) + 1):
1019-
thispart = os.path.join(*parts[:i])
1020-
if not os.path.exists(thispart):
1021-
os.makedirs(thispart, mode)
1022-
1023-
except OSError as err:
1024-
# Reraise the error unless it's about an already existing directory
1025-
if err.errno != errno.EEXIST or not os.path.isdir(newdir):
1026-
raise
1027-
1015+
# this functionality is now in core python as of 3.2
1016+
# LPY DROP
1017+
if six.PY3:
1018+
os.makedirs(newdir, mode=mode, exist_ok=True)
1019+
else:
1020+
try:
1021+
os.makedirs(newdir, mode=mode)
1022+
except OSError as exception:
1023+
if exception.errno != errno.EEXIST:
1024+
raise
10281025

10291026
class GetRealpathAndStat(object):
10301027
def __init__(self):

0 commit comments

Comments
 (0)
0