[PATCH 3 of 4 STABLE] debuglocks: inform about lock corruption if readlink() returns empty string

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sat Apr 29 04:38:09 EDT 2017


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1493454423 -32400
#      Sat Apr 29 17:27:03 2017 +0900
# Branch stable
# Node ID b64713f57a22301b6f481cd8e401542f46356c94
# Parent  d1bf658c4ea6d1f87328884bc00f2b91d884a6d9
debuglocks: inform about lock corruption if readlink() returns empty string

Before this patch, if corrupted lock file makes vfs.readlink() return
empty string, "hg debuglocks" shows just empty string as "locker".

This patch makes debuglocks inform about lock corruption, if
readlink() returns empty string.

Newly added test is executed only on no-symlink platform, because it
isn't portable to create empty symlink.

  - man page of symlink() on Linux explicitly describes that it causes
    ENOENT at creation of empty symlink

  - POSIX specification for symlink() doesn't describe about empty
    symlink explicitly

    http://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html

    AFAIK, (Open)Solaris can, but MacOS X can't.

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1192,6 +1192,8 @@ def debuglocks(ui, repo, **opts):
                     else:
                         locker = 'user %s, process %s, host %s' \
                                  % (user, pid, host)
+                elif not locker.strip():
+                    locker = 'user %s, but corrupted' % (user)
                 ui.write(("%-6s %s (%ds)\n") % (name + ":", locker, age))
                 return 1
             except OSError as e:
diff --git a/tests/test-no-symlinks.t b/tests/test-no-symlinks.t
--- a/tests/test-no-symlinks.t
+++ b/tests/test-no-symlinks.t
@@ -57,3 +57,18 @@ Bundle and extract again
   a
   $ cat b2.lnk && echo
   d/b
+
+Test handling lock corruption
+
+  $ hg debuglocks
+  lock:  free
+  wlock: free
+
+(emulate lock corruption by empty file)
+
+  $ printf '' > .hg/wlock
+
+  $ hg debuglocks
+  lock:  free
+  wlock: user *, but corrupted (*s) (glob)
+  [1]


More information about the Mercurial-devel mailing list