mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Enhance 'which' decorator reliability for peculiar environments
This commit is contained in:
parent
30ea94439c
commit
1c59eedec2
1 changed files with 7 additions and 15 deletions
|
@ -520,11 +520,7 @@ def which(exe=None):
|
|||
# executable in cwd or fullpath
|
||||
return exe
|
||||
|
||||
# default path based on busybox's default
|
||||
default_path = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
|
||||
search_path = os.environ.get('PATH', default_path)
|
||||
path_ext = os.environ.get('PATHEXT', '.EXE')
|
||||
ext_list = path_ext.split(';')
|
||||
ext_list = os.environ.get('PATHEXT', '.EXE').split(';')
|
||||
|
||||
@real_memoize
|
||||
def _exe_has_ext():
|
||||
|
@ -541,7 +537,9 @@ def which(exe=None):
|
|||
continue
|
||||
return False
|
||||
|
||||
search_path = search_path.split(os.pathsep)
|
||||
# enhance POSIX path for the reliability at some environments, when $PATH is changing
|
||||
default_path = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
|
||||
search_path = list(set(os.pathsep.join([os.environ.get('PATH', ''), default_path]).split(os.pathsep)))
|
||||
for path in search_path:
|
||||
full_path = os.path.join(path, exe)
|
||||
if _is_executable_file_or_link(full_path):
|
||||
|
@ -554,16 +552,10 @@ def which(exe=None):
|
|||
# safely rely on that behavior
|
||||
if _is_executable_file_or_link(full_path + ext):
|
||||
return full_path + ext
|
||||
log.trace(
|
||||
'{0!r} could not be found in the following search '
|
||||
'path: {1!r}'.format(
|
||||
exe, search_path
|
||||
)
|
||||
)
|
||||
log.trace('{0!r} could not be found in the following search path: {1!r}'.format(exe, search_path))
|
||||
else:
|
||||
log.error(
|
||||
'No executable was passed to be searched by salt.utils.which()'
|
||||
)
|
||||
log.error('No executable was passed to be searched by salt.utils.which()')
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue