Mercurial > hg
changeset 30445:1ce4c2062ab0
posix: simplify checkexec check
Use a slightly simpler logic that in some cases can avoid an unnecessary chmod
and stat.
Instead of flipping the X bits, make it more clear that we rely on no X bits
being set on initial file creation, and that at least some of them stick after
they all have been set.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Wed, 14 Jan 2015 01:15:26 +0100 |
parents | b1ce25a40826 |
children | b324b4e431e5 |
files | mercurial/posix.py |
diffstat | 1 files changed, 5 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/posix.py Thu Nov 17 12:59:36 2016 +0100 +++ b/mercurial/posix.py Wed Jan 14 01:15:26 2015 +0100 @@ -166,16 +166,16 @@ fh, fn = tempfile.mkstemp(dir=cachedir, prefix='hg-checkexec-') try: os.close(fh) - m = os.stat(fn).st_mode & 0o777 - new_file_has_exec = m & EXECFLAGS - os.chmod(fn, m ^ EXECFLAGS) - exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0o777) == m) + m = os.stat(fn).st_mode + if m & EXECFLAGS: + return False + os.chmod(fn, m & 0o777 | EXECFLAGS) + return os.stat(fn).st_mode & EXECFLAGS 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"""