opener: do not create "foo" directory when writing to "foo/" stable
authorMartin Geisler <mg@aragost.com>
Fri, 29 Oct 2010 12:50:08 +0200
branchstable
changeset 12877 551aa6e27929
parent 12876 a3b182dd548a
child 12878 1634287b6ab1
opener: do not create "foo" directory when writing to "foo/" The directories were not cleaned up when the subsequent open failed and this would confuse things like qnew.
mercurial/util.py
--- a/mercurial/util.py	Fri Oct 29 14:47:45 2010 +0200
+++ b/mercurial/util.py	Fri Oct 29 12:50:08 2010 +0200
@@ -863,9 +863,11 @@
                 nlink = nlinks(f)
             except OSError:
                 nlink = 0
-                d = os.path.dirname(f)
-                if not os.path.isdir(d):
-                    makedirs(d, self.createmode)
+                dirname, basename = os.path.split(f)
+                # Avoid calling makedirs when the path points to a
+                # directory -- the open will raise IOError below.
+                if basename and not os.path.isdir(dirname):
+                    makedirs(dirname, self.createmode)
             if atomictemp:
                 return atomictempfile(f, mode, self.createmode)
             if nlink > 1: