util: move checkexec() to posix.py and return False on Windows
authorAdrian Buehlmann <adrian@cadifra.com>
Mon, 04 Apr 2011 11:41:54 +0200
changeset 13879 5b0a3f6cbead
parent 13878 a8d13ee0ce68
child 13880 255009c77741
util: move checkexec() to posix.py and return False on Windows
mercurial/posix.py
mercurial/util.py
mercurial/windows.py
--- a/mercurial/posix.py	Mon Apr 04 16:21:59 2011 -0500
+++ b/mercurial/posix.py	Mon Apr 04 11:41:54 2011 +0200
@@ -7,7 +7,7 @@
 
 from i18n import _
 import osutil
-import os, sys, errno, stat, getpass, pwd, grp
+import os, sys, errno, stat, getpass, pwd, grp, tempfile
 
 posixfile = open
 nulldev = '/dev/null'
@@ -108,6 +108,33 @@
         # Turn off all +x bits
         os.chmod(f, s & 0666)
 
+def checkexec(path):
+    """
+    Check whether the given path is on a filesystem with UNIX-like exec flags
+
+    Requires a directory (like /foo/.hg)
+    """
+
+    # VFAT on some Linux versions can flip mode but it doesn't persist
+    # a FS remount. Frequently we can detect it if files are created
+    # with exec bit on.
+
+    try:
+        EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
+        fh, fn = tempfile.mkstemp(dir=path, prefix='hg-checkexec-')
+        try:
+            os.close(fh)
+            m = os.stat(fn).st_mode & 0777
+            new_file_has_exec = m & EXECFLAGS
+            os.chmod(fn, m ^ EXECFLAGS)
+            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
+        finally:
+            os.unlink(fn)
+    except (IOError, OSError):
+        # we don't care, the user probably won't be able to commit anyway
+        return False
+    return not (new_file_has_exec or exec_flags_cannot_flip)
+
 def set_binary(fd):
     pass
 
--- a/mercurial/util.py	Mon Apr 04 16:21:59 2011 -0500
+++ b/mercurial/util.py	Mon Apr 04 11:41:54 2011 +0200
@@ -683,33 +683,6 @@
 
     return ''.join(result)
 
-def checkexec(path):
-    """
-    Check whether the given path is on a filesystem with UNIX-like exec flags
-
-    Requires a directory (like /foo/.hg)
-    """
-
-    # VFAT on some Linux versions can flip mode but it doesn't persist
-    # a FS remount. Frequently we can detect it if files are created
-    # with exec bit on.
-
-    try:
-        EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
-        fh, fn = tempfile.mkstemp(dir=path, prefix='hg-checkexec-')
-        try:
-            os.close(fh)
-            m = os.stat(fn).st_mode & 0777
-            new_file_has_exec = m & EXECFLAGS
-            os.chmod(fn, m ^ EXECFLAGS)
-            exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
-        finally:
-            os.unlink(fn)
-    except (IOError, OSError):
-        # we don't care, the user probably won't be able to commit anyway
-        return False
-    return not (new_file_has_exec or exec_flags_cannot_flip)
-
 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
--- a/mercurial/windows.py	Mon Apr 04 16:21:59 2011 -0500
+++ b/mercurial/windows.py	Mon Apr 04 11:41:54 2011 +0200
@@ -132,6 +132,9 @@
 def set_flags(f, l, x):
     pass
 
+def checkexec(path):
+    return False
+
 def set_binary(fd):
     # When run without console, pipes may expose invalid
     # fileno(), usually set to -1.