changeset 30447:0d87b1caed92

posix: move checklink test file to .hg/cache This avoids unnecessary churn in the working directory. It is not necessarily a fully valid assumption that .hg/cache is on the same filesystem as the working directory, but I think it is an acceptable approximation. It could also be the case that different parts of the working directory is on different mount points so checking in the root folder could also be wrong.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 17 Nov 2016 12:59:36 +0100
parents b324b4e431e5
children 8836f13e3c5b
files mercurial/posix.py
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/posix.py	Wed Jan 14 01:15:26 2015 +0100
+++ b/mercurial/posix.py	Thu Nov 17 12:59:36 2016 +0100
@@ -219,9 +219,16 @@
     # mktemp is not racy because symlink creation will fail if the
     # file already exists
     while True:
-        name = tempfile.mktemp(dir=path, prefix='hg-checklink-')
+        cachedir = os.path.join(path, '.hg', 'cache')
+        if os.path.isdir(cachedir):
+            checkdir = cachedir
+        else:
+            checkdir = path
+            cachedir = None
+        name = tempfile.mktemp(dir=checkdir, prefix='checklink-')
         try:
-            fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-')
+            fd = tempfile.NamedTemporaryFile(dir=checkdir,
+                                             prefix='hg-checklink-')
             try:
                 os.symlink(os.path.basename(fd.name), name)
                 os.unlink(name)