util: postpone and reorder parent calculation in makedirs
authorAdrian Buehlmann <adrian@cadifra.com>
Thu, 25 Aug 2011 11:03:16 +0200
changeset 15058 81f33be0ea79
parent 15057 774da7121fc9
child 15061 86380f24e697
util: postpone and reorder parent calculation in makedirs
mercurial/util.py
--- a/mercurial/util.py	Thu Aug 25 20:21:04 2011 -0400
+++ b/mercurial/util.py	Thu Aug 25 11:03:16 2011 +0200
@@ -779,13 +779,15 @@
 
 def makedirs(name, mode=None):
     """recursive directory creation with parent mode inheritance"""
-    parent = os.path.abspath(os.path.dirname(name))
     try:
         os.mkdir(name)
     except OSError, err:
         if err.errno == errno.EEXIST:
             return
-        if not name or parent == name or err.errno != errno.ENOENT:
+        if err.errno != errno.ENOENT or not name:
+            raise
+        parent = os.path.dirname(os.path.abspath(name))
+        if parent == name:
             raise
         makedirs(parent, mode)
         os.mkdir(name)