##// END OF EJS Templates
util: move checkexec() to posix.py and return False on Windows
Adrian Buehlmann -
r13879:5b0a3f6c default
parent child Browse files
Show More
@@ -7,7 +7,7 b''
7
7
8 from i18n import _
8 from i18n import _
9 import osutil
9 import osutil
10 import os, sys, errno, stat, getpass, pwd, grp
10 import os, sys, errno, stat, getpass, pwd, grp, tempfile
11
11
12 posixfile = open
12 posixfile = open
13 nulldev = '/dev/null'
13 nulldev = '/dev/null'
@@ -108,6 +108,33 b' def set_flags(f, l, x):'
108 # Turn off all +x bits
108 # Turn off all +x bits
109 os.chmod(f, s & 0666)
109 os.chmod(f, s & 0666)
110
110
111 def checkexec(path):
112 """
113 Check whether the given path is on a filesystem with UNIX-like exec flags
114
115 Requires a directory (like /foo/.hg)
116 """
117
118 # VFAT on some Linux versions can flip mode but it doesn't persist
119 # a FS remount. Frequently we can detect it if files are created
120 # with exec bit on.
121
122 try:
123 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
124 fh, fn = tempfile.mkstemp(dir=path, prefix='hg-checkexec-')
125 try:
126 os.close(fh)
127 m = os.stat(fn).st_mode & 0777
128 new_file_has_exec = m & EXECFLAGS
129 os.chmod(fn, m ^ EXECFLAGS)
130 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
131 finally:
132 os.unlink(fn)
133 except (IOError, OSError):
134 # we don't care, the user probably won't be able to commit anyway
135 return False
136 return not (new_file_has_exec or exec_flags_cannot_flip)
137
111 def set_binary(fd):
138 def set_binary(fd):
112 pass
139 pass
113
140
@@ -683,33 +683,6 b' def fspath(name, root):'
683
683
684 return ''.join(result)
684 return ''.join(result)
685
685
686 def checkexec(path):
687 """
688 Check whether the given path is on a filesystem with UNIX-like exec flags
689
690 Requires a directory (like /foo/.hg)
691 """
692
693 # VFAT on some Linux versions can flip mode but it doesn't persist
694 # a FS remount. Frequently we can detect it if files are created
695 # with exec bit on.
696
697 try:
698 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
699 fh, fn = tempfile.mkstemp(dir=path, prefix='hg-checkexec-')
700 try:
701 os.close(fh)
702 m = os.stat(fn).st_mode & 0777
703 new_file_has_exec = m & EXECFLAGS
704 os.chmod(fn, m ^ EXECFLAGS)
705 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
706 finally:
707 os.unlink(fn)
708 except (IOError, OSError):
709 # we don't care, the user probably won't be able to commit anyway
710 return False
711 return not (new_file_has_exec or exec_flags_cannot_flip)
712
713 def checklink(path):
686 def checklink(path):
714 """check whether the given path is on a symlink-capable filesystem"""
687 """check whether the given path is on a symlink-capable filesystem"""
715 # mktemp is not racy because symlink creation will fail if the
688 # mktemp is not racy because symlink creation will fail if the
@@ -132,6 +132,9 b' def sshargs(sshcmd, host, user, port):'
132 def set_flags(f, l, x):
132 def set_flags(f, l, x):
133 pass
133 pass
134
134
135 def checkexec(path):
136 return False
137
135 def set_binary(fd):
138 def set_binary(fd):
136 # When run without console, pipes may expose invalid
139 # When run without console, pipes may expose invalid
137 # fileno(), usually set to -1.
140 # fileno(), usually set to -1.
General Comments 0
You need to be logged in to leave comments. Login now