symlinks: check whether a filesystem supports symlinks
authorMatt Mackall <mpm@selenic.com>
Fri, 29 Dec 2006 20:04:31 -0600
changeset 3998 315d47991fd4
parent 3997 3f0ba82c103f
child 3999 0b740dcf0cf1
symlinks: check whether a filesystem supports symlinks
mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -713,6 +713,18 @@ def execfunc(path, fallback):
         return lambda x: is_exec(os.path.join(path, x))
     return fallback
 
+def checksymlink(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)
+    try:
+        os.symlink(".", name)
+        os.unlink(name)
+        return True
+    except OSError:
+        return False
+
 # Platform specific variants
 if os.name == 'nt':
     import msvcrt