Patchwork [STABLE] util.checkcase: don't abort on broken symlinks

login
register
mail settings
Submitter Siddharth Agarwal
Date May 3, 2015, 7:50 p.m.
Message ID <d4e500c021ef15886dfd.1430682634@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8865/
State Accepted
Commit 986a5c23b1c14954e6ddc3fdcc0b6edfb019b5a0
Headers show

Comments

Siddharth Agarwal - May 3, 2015, 7:50 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1430682555 25200
#      Sun May 03 12:49:15 2015 -0700
# Branch stable
# Node ID d4e500c021ef15886dfdae43165292774d6f4b84
# Parent  c48850339988bb8a5048c93ce1285304b96e0887
util.checkcase: don't abort on broken symlinks

One case where that would happen is while trying to resolve a subrepo, if the
path to the subrepo was actually a broken symlink. This bug was exposed by an
hg-git test.
Matt Mackall - May 4, 2015, 4:49 p.m.
On Sun, 2015-05-03 at 12:50 -0700, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1430682555 25200
> #      Sun May 03 12:49:15 2015 -0700
> # Branch stable
> # Node ID d4e500c021ef15886dfdae43165292774d6f4b84
> # Parent  c48850339988bb8a5048c93ce1285304b96e0887
> util.checkcase: don't abort on broken symlinks

Queued for stable, thanks.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -877,7 +877,7 @@  def checkcase(path):
     Requires a path (like /foo/.hg) ending with a foldable final
     directory component.
     """
-    s1 = os.stat(path)
+    s1 = os.lstat(path)
     d, b = os.path.split(path)
     b2 = b.upper()
     if b == b2:
@@ -886,7 +886,7 @@  def checkcase(path):
             return True # no evidence against case sensitivity
     p2 = os.path.join(d, b2)
     try:
-        s2 = os.stat(p2)
+        s2 = os.lstat(p2)
         if s2 == s1:
             return False
         return True
diff --git a/tests/test-subrepo-git.t b/tests/test-subrepo-git.t
--- a/tests/test-subrepo-git.t
+++ b/tests/test-subrepo-git.t
@@ -381,6 +381,20 @@  Don't crash if the subrepo is missing
   $ hg commit --subrepos -qm missing
   abort: subrepo s is missing (in subrepo s)
   [255]
+
+#if symlink
+Don't crash if subrepo is a broken symlink
+  $ ln -s broken s
+  $ hg status -S
+  $ hg push -q
+  abort: subrepo s is missing (in subrepo s)
+  [255]
+  $ hg commit --subrepos -qm missing
+  abort: subrepo s is missing (in subrepo s)
+  [255]
+  $ rm s
+#endif
+
   $ hg update -C 2> /dev/null
   cloning subrepo s from $TESTTMP/gitroot
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved