[PATCH]change posix test for symlinks
DeathGorePain
deathgorepain at users.sourceforge.net
Sun Jul 28 12:28:57 CDT 2013
Hello,
I've been having problems with hg leaving artifacts when the repository
/ working directory is mounted on sshfs. hg-checklink-* linking to the
`hg root` are left in root of the repository and render all operations
slow. In somebody else's words (stackoverflow).
<http://stackoverflow.com/questions/5213876/mercurial-hg-checklinks-recursive-symlink-over-nfs-samba-sshfs-network-drive>
I have not figured out how your tests work (confusing output) :/ But a
local test (sudo cp posix.py ...) returned favorable results and the
artifacts don't exist anymore.
Please find the patch below.
Kind regards,
DeathGorePain
_________________________
# HG changeset patch
# User DeathGorePain <deathgorepain at users.sourceforge.net>
# Date 1375031974 0
# Node ID c7a9ec5eec435af3746e7d4969a4433b4f48649d
# Parent 004f965630d907a3417a93e87d056ad4c2dab541
hg-checklink:change posix test for symlinks
old:link to currentdir(hg root), if fail: leave artefacts
new:link to temporary file and clean up when method exits
diff -r 004f965630d9 -r c7a9ec5eec43 mercurial/posix.py
--- a/mercurial/posix.py Fri Jul 12 11:14:42 2013 +0900
+++ b/mercurial/posix.py Sun Jul 28 17:19:34 2013 +0000
@@ -152,13 +152,34 @@
"""check whether the given path is on a symlink-capable filesystem"""
# mktemp is not racy because symlink creation will fail if the
# file already exists
- name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
+
+ # Will create a temporary file in the path
+ # Try to symlink to it
+ # And clean up all traces if anything goes wrong
+ symlink_name = "symlink"
+
+ sourcefile = tempfile.NamedTemporaryFile(
+ dir=path,
+ delete=True,
+ prefix="hg-checklink-"
+ )
try:
- os.symlink(".", name)
- os.unlink(name)
- return True
+ symlink_name = os.path.join(
+ os.path.dirname(sourcefile.name),
+ symlink_name
+ )
+ if os.path.exists(sourcefile.name):
+ try:
+ os.symlink(sourcefile.name, symlink_name)
+ os.unlink(symlink_name)
+ return True
+ except (OSError, AttributeError):
+ if os.path.exists(symlink_name):
+ os.unlink(symlink_name)
except (OSError, AttributeError):
- return False
+ pass
+
+ return False
def checkosfilename(path):
'''Check that the base-relative path is a valid filename on this
platform.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130728/aab6ca3d/attachment.html>
More information about the Mercurial-devel
mailing list