Skip to content

Commit

Permalink
[Plugin] Check if a path exists inside a container in add_dir_listing()
Browse files Browse the repository at this point in the history
Currently, add_dir_listing() checks if a path exists outside of a
container, and when we call the command for a container, it fails to
collect any listing. This patch adds a new function
container_path_exists() that checks for the specified path in
add_dir_listing() inside the container.

Resolves: #3805

Signed-off-by: Jose Castillo <[email protected]>
Signed-off-by: Pavel Moravec <[email protected]>
  • Loading branch information
jcastill authored and pmoravec committed Nov 20, 2024
1 parent 24e270e commit fdfaa3c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,11 @@ def add_dir_listing(self, paths, tree=False, recursive=False, chroot=True,
if isinstance(paths, str):
paths = [paths]

paths = [p for p in paths if self.path_exists(p)]
if container:
paths = [p for p in paths if
self.container_path_exists(p, container=container)]
else:
paths = [p for p in paths if self.path_exists(p)]

if not tree:
options = f"alZ{'R' if recursive else ''}"
Expand Down Expand Up @@ -3410,6 +3414,22 @@ def setup_verify(self):
if verify_cmd:
self.add_cmd_output(verify_cmd)

def container_path_exists(self, path, container):
"""Check if a path exists inside a container before
collecting a dir listing
:param path: The canonical path for a specific file/directory
in a container
:type path: ``str``
:param container: The container where to check for the path
:type container: ``str``
:returns: True if the path exists in the container, else False
:rtype: ``bool``
"""
return self.exec_cmd(f"test -e {path}", container=container)

def path_exists(self, path):
"""Helper to call the sos.utilities wrapper that allows the
corresponding `os` call to account for sysroot
Expand Down

0 comments on commit fdfaa3c

Please sign in to comment.