comparison mercurial/util.py @ 5739:45fa7b1c5d4c

checkexec: fix VFAT tempfile droppings with more modern Linux kernels More recent Linux kernels don't pretend to allow any bogus chmods on VFAT.
author Matt Mackall <mpm@selenic.com>
date Thu, 27 Dec 2007 23:55:40 -0600
parents 76dd039c2bad
children 9046a4f6a07c
comparison
equal deleted inserted replaced
5738:2a54e2b177b6 5739:45fa7b1c5d4c
846 """ 846 """
847 Check whether the given path is on a filesystem with UNIX-like exec flags 847 Check whether the given path is on a filesystem with UNIX-like exec flags
848 848
849 Requires a directory (like /foo/.hg) 849 Requires a directory (like /foo/.hg)
850 """ 850 """
851
852 # VFAT on some Linux versions can flip mode but it doesn't persist
853 # a FS remount. Frequently we can detect it if files are created
854 # with exec bit on.
855
851 try: 856 try:
852 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH 857 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
853 fh, fn = tempfile.mkstemp("", "", path) 858 fh, fn = tempfile.mkstemp("", "", path)
854 os.close(fh) 859 try:
855 m = os.stat(fn).st_mode 860 os.close(fh)
856 # VFAT on Linux can flip mode but it doesn't persist a FS remount. 861 m = os.stat(fn).st_mode & 0777
857 # frequently we can detect it if files are created with exec bit on. 862 new_file_has_exec = m & EXECFLAGS
858 new_file_has_exec = m & EXECFLAGS 863 os.chmod(fn, m ^ EXECFLAGS)
859 os.chmod(fn, m ^ EXECFLAGS) 864 exec_flags_cannot_flip = (os.stat(fn).st_mode == m)
860 exec_flags_cannot_flip = (os.stat(fn).st_mode == m) 865 finally:
861 os.unlink(fn) 866 os.unlink(fn)
862 except (IOError,OSError): 867 except (IOError, OSError):
863 # we don't care, the user probably won't be able to commit anyway 868 # we don't care, the user probably won't be able to commit anyway
864 return False 869 return False
865 return not (new_file_has_exec or exec_flags_cannot_flip) 870 return not (new_file_has_exec or exec_flags_cannot_flip)
866 871
867 def execfunc(path, fallback): 872 def execfunc(path, fallback):