equal
deleted
inserted
replaced
5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
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' |
14 normpath = os.path.normpath |
14 normpath = os.path.normpath |
15 samestat = os.path.samestat |
15 samestat = os.path.samestat |
106 os.chmod(f, s | (s & 0444) >> 2 & ~umask) |
106 os.chmod(f, s | (s & 0444) >> 2 & ~umask) |
107 elif not x and sx: |
107 elif not x and sx: |
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 |
114 def pconvert(path): |
141 def pconvert(path): |
115 return path |
142 return path |