From fc79ad2c86080583ecb1078bb8841d54b4e0d0bb Mon Sep 17 00:00:00 2001 From: Tristan Maat Date: Mon, 16 Jul 2018 18:01:33 +0100 Subject: utils.py: Allow `list_relative_paths` to list directories --- buildstream/utils.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/buildstream/utils.py b/buildstream/utils.py index b81a6c852..0bbc7a877 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -96,7 +96,7 @@ class FileListResult(): return ret -def list_relative_paths(directory): +def list_relative_paths(directory, *, list_dirs=True): """A generator for walking directory relative paths This generator is useful for checking the full manifest of @@ -110,6 +110,7 @@ def list_relative_paths(directory): Args: directory (str): The directory to list files in + list_dirs (bool): Whether to list directories Yields: Relative filenames in `directory` @@ -136,15 +137,16 @@ def list_relative_paths(directory): # subdirectories in the walked `dirpath`, so we extract # these symlinks from `dirnames` # - for d in dirnames: - fullpath = os.path.join(dirpath, d) - if os.path.islink(fullpath): - yield os.path.join(basepath, d) + if list_dirs: + for d in dirnames: + fullpath = os.path.join(dirpath, d) + if os.path.islink(fullpath): + yield os.path.join(basepath, d) # We've decended into an empty directory, in this case we # want to include the directory itself, but not in any other # case. - if not filenames: + if list_dirs and not filenames: yield relpath # List the filenames in the walked directory -- cgit v1.2.1