mercurial/posix.py
changeset 30448 8836f13e3c5b
parent 30447 0d87b1caed92
child 30555 6a672c3b7860
--- a/mercurial/posix.py	Thu Nov 17 12:59:36 2016 +0100
+++ b/mercurial/posix.py	Wed Jan 14 01:15:26 2015 +0100
@@ -220,6 +220,10 @@
     # file already exists
     while True:
         cachedir = os.path.join(path, '.hg', 'cache')
+        checklink = os.path.join(cachedir, 'checklink')
+        # try fast path, read only
+        if os.path.islink(checklink):
+            return True
         if os.path.isdir(cachedir):
             checkdir = cachedir
         else:
@@ -231,7 +235,13 @@
                                              prefix='hg-checklink-')
             try:
                 os.symlink(os.path.basename(fd.name), name)
-                os.unlink(name)
+                if cachedir is None:
+                    os.unlink(name)
+                else:
+                    try:
+                        os.rename(name, checklink)
+                    except OSError:
+                        os.unlink(name)
                 return True
             except OSError as inst:
                 # link creation might race, try again