# HG changeset patch
# User Marc-Antoine Ruel <maruel@google.com>
# Date 1321566277 21600
#      Thu Nov 17 15:44:37 2011 -0600
# Node ID 7ee7b7426aad050b0989a786568c2a87cb74b1d7
# Parent  eb5ed02d87436bc19b1c25f66004a2e192df50f4
posix: fix findexe() to check for file type and access

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -258,7 +258,7 @@
 
     def findexisting(executable):
         'Will return executable if existing file'
-        if os.path.exists(executable):
+        if os.path.isfile(executable) and os.access(executable, os.X_OK):
             return executable
         return None
 
@@ -268,9 +268,7 @@
     for path in os.environ.get('PATH', '').split(os.pathsep):
         executable = findexisting(os.path.join(path, command))
         if executable is not None:
-            st = os.stat(executable)
-            if (st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)):
-                return executable
+            return executable
     return None
 
 def setsignalhandler():