Fwd: [PATCH] checknlink: use two testfiles
Joel B. Mohler
joel at kiwistrawberry.us
Sat Dec 18 09:18:11 UTC 2010
On Wednesday, December 15, 2010 07:36:43 am Joel B. Mohler wrote:
> ---------- Forwarded Message ----------
>
> Subject: [PATCH] checknlink: use two testfiles
> Date: Tuesday, December 14, 2010, 06:39:54 pm
> From: Adrian Buehlmann <adrian at cadifra.com>
> To: mercurial-devel at selenic.com
I confirm that the patch below fixes my symptoms.
>
> # HG changeset patch
> # User Adrian Buehlmann <adrian at cadifra.com>
> # Date 1292369727 -3600
> # Branch stable
> # Node ID c582de5b6ac6c15cf4c8214c7183fad585eaa4ba
> # Parent dbc546811dd6eb672756f9266d432bb9c1101adb
> checknlink: use two testfiles
>
> works around issue2543
>
> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -719,21 +719,37 @@ def checklink(path):
>
> def checknlink(testfile):
> '''check whether hardlink count reporting works properly'''
> - f = testfile + ".hgtmp"
>
> + # testfile may be open, so we need a separate file for checking to
> + # work around issue2543 (or testfile may get lost on Samba shares)
> + f1 = testfile + ".hgtmp1"
> + if os.path.lexists(f1):
> + return False
> try:
> - os_link(testfile, f)
> - except OSError:
> + posixfile(f1, 'w').close()
> + except IOError:
> return False
>
> + f2 = testfile + ".hgtmp2"
> + fd = None
> try:
> + try:
> + os_link(f1, f2)
> + except OSError:
> + return False
> +
> # nlinks() may behave differently for files on Windows shares if
> # the file is open.
> - fd = open(f)
> - return nlinks(f) > 1
> + fd = open(f2)
> + return nlinks(f2) > 1
> finally:
> - fd.close()
> - os.unlink(f)
> + if fd is not None:
> + fd.close()
> + for f in (f1, f2):
> + try:
> + os.unlink(f)
> + except OSError:
> + pass
>
> return False
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>
> -----------------------------------------
More information about the Mercurial-devel
mailing list