Skip to content

Commit

Permalink
Check execution file method optimization
Browse files Browse the repository at this point in the history
Use os.pathsep instead of the hard coded path separator ':'.
os.pathsep represents the path separator for the current operating system .
Use os. path. isfile() instead of os. path. exists() to check if the given path is a file.
This can avoid misjudging the directory as an executable file.

Signed-off-by: wulei01 <[email protected]>
  • Loading branch information
wulei01 committed Aug 9, 2023
1 parent 35dc287 commit 2363f96
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions avocado/utils/iso9660.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def has_userland_tool(executable):
:rtype: bool
"""
if os.path.isabs(executable):
return os.path.exists(executable)
return os.path.isfile(executable)
else:
for path in os.environ["PATH"].split(":"):
if os.path.exists(os.path.join(path, executable)):
for path in os.environ["PATH"].split(os.pathsep):
if os.path.isfile(os.path.join(path, executable)):
return True
return False

Expand Down

0 comments on commit 2363f96

Please sign in to comment.