Patchwork change posix test for symlinks

login
register
mail settings
Submitter DeathGorePain
Date July 28, 2013, 5:28 p.m.
Message ID <51F554D9.4060409@users.sourceforge.net>
Download mbox | patch
Permalink /patch/1977/
State Rejected
Headers show

Comments

DeathGorePain - July 28, 2013, 5:28 p.m.
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
Jordi Gutiérrez Hermoso - July 28, 2013, 6:08 p.m.
On 28 July 2013 13:28, DeathGorePain
<deathgorepain@users.sourceforge.net> wrote:
> Kind regards,
> DeathGorePain

Kind, eh? o.O

- Jordi G. H.
DeathGorePain - July 28, 2013, 7:26 p.m.
All a matter of perspective :)

Cheers,
DeathGorePain
Le dim. 28 juil. 2013 18:08:21 UTC, Jordi Gutiérrez Hermoso a écrit :
> On 28 July 2013 13:28, DeathGorePain
> <deathgorepain@users.sourceforge.net> wrote:
>> Kind regards,
>> DeathGorePain
>
> Kind, eh? o.O
>
> - Jordi G. H.

Patch

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