comparison mercurial/posix.py @ 15504:7ee7b7426aad

posix: fix findexe() to check for file type and access
author Marc-Antoine Ruel <maruel@google.com>
date Thu, 17 Nov 2011 15:44:37 -0600
parents 6eff984d8e76
children 1fa41d1f1351
comparison
equal deleted inserted replaced
15503:eb5ed02d8743 15504:7ee7b7426aad
256 if sys.platform == 'OpenVMS': 256 if sys.platform == 'OpenVMS':
257 return command 257 return command
258 258
259 def findexisting(executable): 259 def findexisting(executable):
260 'Will return executable if existing file' 260 'Will return executable if existing file'
261 if os.path.exists(executable): 261 if os.path.isfile(executable) and os.access(executable, os.X_OK):
262 return executable 262 return executable
263 return None 263 return None
264 264
265 if os.sep in command: 265 if os.sep in command:
266 return findexisting(command) 266 return findexisting(command)
267 267
268 for path in os.environ.get('PATH', '').split(os.pathsep): 268 for path in os.environ.get('PATH', '').split(os.pathsep):
269 executable = findexisting(os.path.join(path, command)) 269 executable = findexisting(os.path.join(path, command))
270 if executable is not None: 270 if executable is not None:
271 st = os.stat(executable) 271 return executable
272 if (st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)):
273 return executable
274 return None 272 return None
275 273
276 def setsignalhandler(): 274 def setsignalhandler():
277 pass 275 pass
278 276