From patchwork Sat Oct 24 16:32:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [4,of,5,rfc] posix: move checklink test file to .hg/cache From: Mads Kiilerich X-Patchwork-Id: 11236 Message-Id: <3a6d970e2d2f86b51b6a.1445704322@localhost.localdomain> To: mercurial-devel@selenic.com Date: Sat, 24 Oct 2015 18:32:02 +0200 # HG changeset patch # User Mads Kiilerich # Date 1445704208 -7200 # Sat Oct 24 18:30:08 2015 +0200 # Branch stable # Node ID 3a6d970e2d2f86b51b6ad0223a4da1a3a3e19bc9 # Parent 5921bcc389073dfdb4a44284db5ee00bcbb0c499 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. diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -214,9 +214,15 @@ def checklink(path): """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-') + 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)