diff options
Diffstat (limited to 'buildstream/utils.py')
-rw-r--r-- | buildstream/utils.py | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py index c8d79c95a..76f95637e 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -111,7 +111,7 @@ class FileListResult(): return ret -def list_relative_paths(directory, *, list_dirs=True): +def list_relative_paths(directory): """A generator for walking directory relative paths This generator is useful for checking the full manifest of @@ -125,13 +125,26 @@ def list_relative_paths(directory, *, list_dirs=True): Args: directory (str): The directory to list files in - list_dirs (bool): Whether to list directories Yields: Relative filenames in `directory` """ for (dirpath, dirnames, filenames) in os.walk(directory): + # os.walk does not decend into symlink directories, which + # makes sense because otherwise we might have redundant + # directories, or end up descending into directories outside + # of the walk() directory. + # + # But symlinks to directories are still identified as + # subdirectories in the walked `dirpath`, so we extract + # these symlinks from `dirnames` and add them to `filenames`. + # + for d in dirnames: + fullpath = os.path.join(dirpath, d) + if os.path.islink(fullpath): + filenames.append(d) + # Modifying the dirnames directly ensures that the os.walk() generator # allows us to specify the order in which they will be iterated. dirnames.sort() @@ -143,25 +156,10 @@ def list_relative_paths(directory, *, list_dirs=True): # `directory`, prefer to have no prefix in that case. basepath = relpath if relpath != '.' and dirpath != directory else '' - # os.walk does not decend into symlink directories, which - # makes sense because otherwise we might have redundant - # directories, or end up descending into directories outside - # of the walk() directory. - # - # But symlinks to directories are still identified as - # subdirectories in the walked `dirpath`, so we extract - # these symlinks from `dirnames` - # - 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 list_dirs and not filenames: + if not filenames: yield relpath # List the filenames in the walked directory |