summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2018-07-16 18:01:33 +0100
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-07-18 14:11:03 +0900
commitfc79ad2c86080583ecb1078bb8841d54b4e0d0bb (patch)
tree21d8d2d1650924ce7cfb955fd5f931174d126633
parentb8543f8ac4a5d63703884a67fbe169954b6db287 (diff)
downloadbuildstream-fc79ad2c86080583ecb1078bb8841d54b4e0d0bb.tar.gz
utils.py: Allow `list_relative_paths` to list directories
-rw-r--r--buildstream/utils.py14
1 files 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