changeset 30555:6a672c3b7860

posix: give the cached symlink a real target The NamedTemporaryFile file is cleared up so checklink ends up as a dangling symlink, causing cp -r in tests to complain on both Solaris and OS X. Use a permanent file instead when there is a .hg/cache directory.
author Martijn Pieters <mjpieters@fb.com>
date Wed, 30 Nov 2016 16:39:36 +0000
parents 1775975dd439
children c059286a0f9c
files mercurial/posix.py tests/test-clone.t tests/test-hardlinks.t tests/test-tags.t
diffstat 4 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/posix.py	Tue Nov 29 07:20:03 2016 -0800
+++ b/mercurial/posix.py	Wed Nov 30 16:39:36 2016 +0000
@@ -231,10 +231,18 @@
             cachedir = None
         name = tempfile.mktemp(dir=checkdir, prefix='checklink-')
         try:
-            fd = tempfile.NamedTemporaryFile(dir=checkdir,
-                                             prefix='hg-checklink-')
+            fd = None
+            if cachedir is None:
+                fd = tempfile.NamedTemporaryFile(dir=checkdir,
+                                                 prefix='hg-checklink-')
+                target = os.path.basename(fd.name)
+            else:
+                # create a fixed file to link to; doesn't matter if it
+                # already exists.
+                target = 'checklink-target'
+                open(os.path.join(cachedir, target), 'w').close()
             try:
-                os.symlink(os.path.basename(fd.name), name)
+                os.symlink(target, name)
                 if cachedir is None:
                     os.unlink(name)
                 else:
@@ -249,7 +257,8 @@
                     continue
                 raise
             finally:
-                fd.close()
+                if fd is not None:
+                    fd.close()
         except AttributeError:
             return False
         except OSError as inst:
--- a/tests/test-clone.t	Tue Nov 29 07:20:03 2016 -0800
+++ b/tests/test-clone.t	Wed Nov 30 16:39:36 2016 +0000
@@ -33,6 +33,7 @@
   branch2-served
   checkisexec
   checklink
+  checklink-target
   checknoexec
   rbc-names-v1
   rbc-revs-v1
@@ -50,6 +51,7 @@
   branch2-served
   checkisexec
   checklink
+  checklink-target
 
   $ cat a
   a
--- a/tests/test-hardlinks.t	Tue Nov 29 07:20:03 2016 -0800
+++ b/tests/test-hardlinks.t	Wed Nov 30 16:39:36 2016 +0000
@@ -212,6 +212,8 @@
   2 r4/.hg/branch
   2 r4/.hg/cache/branch2-served
   2 r4/.hg/cache/checkisexec
+  3 r4/.hg/cache/checklink (?)
+  ? r4/.hg/cache/checklink-target (glob)
   2 r4/.hg/cache/checknoexec
   2 r4/.hg/cache/rbc-names-v1
   2 r4/.hg/cache/rbc-revs-v1
@@ -250,6 +252,7 @@
   1 r4/.hg/branch
   2 r4/.hg/cache/branch2-served
   2 r4/.hg/cache/checkisexec
+  2 r4/.hg/cache/checklink-target
   2 r4/.hg/cache/checknoexec
   2 r4/.hg/cache/rbc-names-v1
   2 r4/.hg/cache/rbc-revs-v1
--- a/tests/test-tags.t	Tue Nov 29 07:20:03 2016 -0800
+++ b/tests/test-tags.t	Wed Nov 30 16:39:36 2016 +0000
@@ -674,6 +674,7 @@
   branch2-served
   checkisexec
   checklink
+  checklink-target
   hgtagsfnodes1
   rbc-names-v1
   rbc-revs-v1
@@ -700,6 +701,7 @@
   branch2-served
   checkisexec
   checklink
+  checklink-target
   hgtagsfnodes1
   rbc-names-v1
   rbc-revs-v1