[PATCH 1 of 2 STABLE] opener: raise IOError on paths ending in '/'

Adrian Buehlmann adrian at cadifra.com
Sun Oct 31 02:32:57 CDT 2010


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1288433569 -7200
# Branch stable
# Node ID cd9700552b22bf12b375fc48a582fd96da721145
# Parent  15ca4bfecfe343cbf53210b19c081676b2a35d3f
opener: raise IOError on paths ending in '/'

This improves 551aa6e27929 and 1634287b6ab1 by making sure we don't
call any further functions (e.g. atomictempfile) if we already know
that the path is not a valid file path.

It's also better not to call nlinks() for such malformed paths, so
let's move the path test out of the OSError exception handler.

As another nice side effect, this patch also fixes a platform dependent
test output variation that happens to have been introduced with 551aa6e27929
(551aa6e27929 causes test-mq-qnew.t to fail on Mac OS X, as reported
by Steve Borho).

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -859,14 +859,15 @@ class opener(object):
 
         nlink = -1
         if mode not in ("r", "rb"):
+            dirname, basename = os.path.split(f)
+            if not basename:
+                code = errno.EISDIR
+                raise IOError(code, os.strerror(code))
             try:
                 nlink = nlinks(f)
             except OSError:
                 nlink = 0
-                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):
+                if not os.path.isdir(dirname):
                     makedirs(dirname, self.createmode)
             if atomictemp:
                 return atomictempfile(f, mode, self.createmode)


More information about the Mercurial-devel mailing list