summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2015-11-19 04:48:44 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2015-11-19 04:48:44 (GMT)
commita82642f9dbdff5253f40d4acee0cbb27aaf34462 (patch)
tree39ae79f83900575d6dba600ebec8deb3917508eb /Lib/os.py
parent41f69f4cc7c977bd202545b8ada01b80a278d0e2 (diff)
downloadcpython-a82642f9dbdff5253f40d4acee0cbb27aaf34462.zip
cpython-a82642f9dbdff5253f40d4acee0cbb27aaf34462.tar.gz
cpython-a82642f9dbdff5253f40d4acee0cbb27aaf34462.tar.bz2
Issue #25583: Avoid incorrect errors raised by os.makedirs(exist_ok=True)
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/os.py b/Lib/os.py
index a8f6a0b..27b241a 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -226,7 +226,7 @@ def makedirs(name, mode=0o777, exist_ok=False):
try:
makedirs(head, mode, exist_ok)
except FileExistsError:
- # be happy if someone already created the path
+ # Defeats race condition when another thread created the path
pass
cdir = curdir
if isinstance(tail, bytes):
@@ -235,8 +235,10 @@ def makedirs(name, mode=0o777, exist_ok=False):
return
try:
mkdir(name, mode)
- except OSError as e:
- if not exist_ok or e.errno != errno.EEXIST or not path.isdir(name):
+ except OSError:
+ # Cannot rely on checking for EEXIST, since the operating system
+ # could give priority to other errors like EACCES or EROFS
+ if not exist_ok or not path.isdir(name):
raise
def removedirs(name):