comparison mercurial/posix.py @ 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
comparison
equal deleted inserted replaced
30446:b324b4e431e5 30447:0d87b1caed92
217 def checklink(path): 217 def checklink(path):
218 """check whether the given path is on a symlink-capable filesystem""" 218 """check whether the given path is on a symlink-capable filesystem"""
219 # mktemp is not racy because symlink creation will fail if the 219 # mktemp is not racy because symlink creation will fail if the
220 # file already exists 220 # file already exists
221 while True: 221 while True:
222 name = tempfile.mktemp(dir=path, prefix='hg-checklink-') 222 cachedir = os.path.join(path, '.hg', 'cache')
223 if os.path.isdir(cachedir):
224 checkdir = cachedir
225 else:
226 checkdir = path
227 cachedir = None
228 name = tempfile.mktemp(dir=checkdir, prefix='checklink-')
223 try: 229 try:
224 fd = tempfile.NamedTemporaryFile(dir=path, prefix='hg-checklink-') 230 fd = tempfile.NamedTemporaryFile(dir=checkdir,
231 prefix='hg-checklink-')
225 try: 232 try:
226 os.symlink(os.path.basename(fd.name), name) 233 os.symlink(os.path.basename(fd.name), name)
227 os.unlink(name) 234 os.unlink(name)
228 return True 235 return True
229 except OSError as inst: 236 except OSError as inst: