summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-12-09 09:08:29 (GMT)
committerGeorg Brandl <georg@python.org>2006-12-09 09:08:29 (GMT)
commitb130743e97410ba2b6c23d69df80e2ecea9d652b (patch)
tree2fa7ce21c234f4bc3ec8386a8617dcb1dc0c7c39 /Lib/os.py
parent66fab425a8d2fb60c3ccfb28ced2d677380f4f30 (diff)
downloadcpython-b130743e97410ba2b6c23d69df80e2ecea9d652b.zip
cpython-b130743e97410ba2b6c23d69df80e2ecea9d652b.tar.gz
cpython-b130743e97410ba2b6c23d69df80e2ecea9d652b.tar.bz2
Patch #1608267: fix a race condition in os.makedirs() is the directory
to be created is already there.
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 2d1b29b..7d44dc4 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -25,6 +25,8 @@ and opendir), and leave all pathname manipulation to os.path
import sys
+from errno import ENOENT, ENOTDIR, EEXIST
+
_names = sys.builtin_module_names
# Note: more names are added to __all__ later.
@@ -160,7 +162,12 @@ def makedirs(name, mode=0777):
if not tail:
head, tail = path.split(head)
if head and tail and not path.exists(head):
- makedirs(head, mode)
+ try:
+ makedirs(head, mode)
+ except OSError, e:
+ # be happy if someone already created the path
+ if e.errno != EEXIST:
+ raise
if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
return
mkdir(name, mode)
@@ -359,8 +366,6 @@ def execvpe(file, args, env):
__all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])
def _execvpe(file, args, env=None):
- from errno import ENOENT, ENOTDIR
-
if env is not None:
func = execve
argrest = (args, env)