summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-02-01 10:45:30 +0000
committerJürg Billeter <j@bitron.ch>2019-02-11 05:12:25 +0000
commitd1da3fb085507a9bc1a576d37008ed5b18319aec (patch)
tree556ec61975a4e51ab3cf18745ec4fe85fe4bdb78
parent89973fb3721a6b02ba1b1b7be46e34fbce137472 (diff)
downloadbuildstream-d1da3fb085507a9bc1a576d37008ed5b18319aec.tar.gz
utils.py: Fix sorting of symlinks to directories
os.walk() resolves symlinks to check whether they point to a directory even when followlinks is set to False. We already work around that broken behavior by extracting symlinks from `dirnames`. However, the sort order was still incorrect as we returned symlinks in dirnames before files and other symlinks. This change fixes this, sorting all files and symlinks in a single list.
-rw-r--r--buildstream/utils.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py
index 224ac6ee8..76f95637e 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -131,17 +131,6 @@ def list_relative_paths(directory):
"""
for (dirpath, dirnames, filenames) in os.walk(directory):
- # Modifying the dirnames directly ensures that the os.walk() generator
- # allows us to specify the order in which they will be iterated.
- dirnames.sort()
- filenames.sort()
-
- relpath = os.path.relpath(dirpath, directory)
-
- # We don't want "./" pre-pended to all the entries in the root of
- # `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
@@ -149,12 +138,23 @@ def list_relative_paths(directory):
#
# But symlinks to directories are still identified as
# subdirectories in the walked `dirpath`, so we extract
- # these symlinks from `dirnames`
+ # these symlinks from `dirnames` and add them to `filenames`.
#
for d in dirnames:
fullpath = os.path.join(dirpath, d)
if os.path.islink(fullpath):
- yield os.path.join(basepath, d)
+ 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()
+ filenames.sort()
+
+ relpath = os.path.relpath(dirpath, directory)
+
+ # We don't want "./" pre-pended to all the entries in the root of
+ # `directory`, prefer to have no prefix in that case.
+ basepath = relpath if relpath != '.' and dirpath != directory else ''
# We've decended into an empty directory, in this case we
# want to include the directory itself, but not in any other