Skip to content

Commit

Permalink
linux: search for commands in /bin, /sbin too
Browse files Browse the repository at this point in the history
Be compatible with distros that don't implement usr merge. If /bin and
/sbin are symlinks to /usr/[s]bin, this could list the same directory
contents again, so refactor the commands variable into a set instead of
an array.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
  • Loading branch information
rohieb authored and Emantor committed Jan 21, 2021
1 parent 27ebbe4 commit 486d01c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions labgridhelper/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,18 @@ def get_commands(command, directories=None):
"""
assert isinstance(command, CommandProtocol), "command must be a CommandProtocol"
out = command.run_check("ls /usr/bin")
out.extend(command.run_check("ls /bin"))
out.extend(command.run_check("ls /usr/sbin"))
out.extend(command.run_check("ls /sbin"))
if directories:
assert isinstance(directories, list), "directories must be a list"
for directory in directories:
out.extend(command.run_check("ls {}".format(directory)))
commands = []
commands = set()
for line in out:
for cmd in line.split(" "):
if cmd:
commands.append(cmd)
commands.add(cmd)

return commands

Expand Down

0 comments on commit 486d01c

Please sign in to comment.