[PATCH] posix findexe function returns non-executable files

Robert Jones rob at redshirtsoftware.com
Thu Aug 25 23:48:32 CDT 2011


opener: posix findexe function returns non-executable files

Make the Posix version of the findexe() function check the file's executable
bits before returning the file.  If the executable bits are not set then the
file is skipped.

The Posix findexe() function claims to do command searching like
which does, but which only returns executable files.  The Posix findexe
function will return any file found in the path, regardless of the file's
permission bits.  This causes problems in other tools, like TortoiseHg,
that expect findexe to return an executable file.

This patch adds a permissions check to the Posix findexe function.  If the
executable bit is not set for any of user, group or other, then the function
continues searching the path.  The patch does not check files that have
path separators in the name.  It is assumed the user added an explicit path
for a reason.  findexe() should not break that assumption.


# HG changeset patch
# User Robert Jones <rob at redshirtsoftware.com>
# Date 1314178961 14400
# Node ID ddb494a4ae579edcb7a3de94a9ccfab39489fc92
# Parent  f1c54569975b1db26667e07649cc95adf4de347c
add check for executable bits on files identified by posix findexe function

diff -r f1c54569975b -r ddb494a4ae57 mercurial/posix.py
--- a/mercurial/posix.py    Wed Aug 24 05:41:31 2011 -0400
+++ b/mercurial/posix.py    Wed Aug 24 05:42:41 2011 -0400
@@ -256,7 +256,9 @@
      for path in os.environ.get('PATH', '').split(os.pathsep):
          executable = findexisting(os.path.join(path, command))
          if executable is not None:
-            return executable
+            st = os.stat(executable)
+            if (st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)):
+                return executable
      return None

  def setsignalhandler():



More information about the Mercurial-devel mailing list