changeset 16320:e11ab387e89c stable

tests: make hghave handle exec bit on Linux with vfat
author Matt Mackall <mpm@selenic.com>
date Sat, 31 Mar 2012 10:44:31 -0500
parents ac0da5caebec
children e1615a24b73a
files tests/hghave
diffstat 1 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/tests/hghave	Sat Mar 31 10:44:31 2012 -0500
+++ b/tests/hghave	Sat Mar 31 10:44:31 2012 -0500
@@ -4,7 +4,7 @@
 prefixed with "no-", the absence of feature is tested.
 """
 import optparse
-import os
+import os, stat
 import re
 import sys
 import tempfile
@@ -64,14 +64,21 @@
         return False
 
 def has_executablebit():
-    fd, path = tempfile.mkstemp(prefix=tempprefix)
-    os.close(fd)
     try:
-        s = os.lstat(path).st_mode
-        os.chmod(path, s | 0100)
-        return (os.lstat(path).st_mode & 0100 != 0)
-    finally:
-        os.remove(path)
+        EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
+        fh, fn = tempfile.mkstemp(dir=".", 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 has_icasefs():
     # Stolen from mercurial.util