]> granicus.if.org Git - python/commitdiff
Patch #1608267: fix a race condition in os.makedirs() is the directory
authorGeorg Brandl <georg@python.org>
Sat, 9 Dec 2006 09:08:29 +0000 (09:08 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 9 Dec 2006 09:08:29 +0000 (09:08 +0000)
to be created is already there.

Lib/os.py
Misc/NEWS

index 2d1b29b57bf422299fe71b04d3d6ce453efe62ec..7d44dc4e65eeee5b7d92117381a83d17cba96e71 100644 (file)
--- 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)
index 648d09ae7728d5c866bdbd32899ce2a714f0e19d..0e408b3a00ddd711dce3b930bd841682150073ed 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -101,6 +101,9 @@ Core and builtins
 Library
 -------
 
+- Patch #1608267: fix a race condition in os.makedirs() is the directory
+  to be created is already there.
+
 - Patch #1610437: fix a tarfile bug with long filename headers.
 
 - Patch #1371075: Make ConfigParser accept optional dict type