util.makedirs: propagate chmod exceptions
authorMads Kiilerich <mads@kiilerich.com>
Mon, 22 Aug 2011 00:35:42 +0200
changeset 15049 79a861b8f553
parent 15048 2f0a3977c939
child 15050 ff3e93686306
util.makedirs: propagate chmod exceptions The existing exception handling was intended to handle mkdir errors. Strange chmod exceptions could thus have strange consequences - or be swallowed.
mercurial/util.py
--- a/mercurial/util.py	Sun Aug 21 20:40:10 2011 +0100
+++ b/mercurial/util.py	Mon Aug 22 00:35:42 2011 +0200
@@ -783,16 +783,15 @@
     parent = os.path.abspath(os.path.dirname(name))
     try:
         os.mkdir(name)
-        if mode is not None:
-            os.chmod(name, mode)
-        return
     except OSError, err:
         if err.errno == errno.EEXIST:
             return
         if not name or parent == name or err.errno != errno.ENOENT:
             raise
-    makedirs(parent, mode)
-    makedirs(name, mode)
+        makedirs(parent, mode)
+        makedirs(name, mode)
+    if mode is not None:
+        os.chmod(name, mode)
 
 def readfile(path):
     fp = open(path, 'rb')