findleaves.py: prevent recursion into symlink loops am: 7829ebfebd am: 7227637308

am: 7cb42e1340

Change-Id: Iab278035e9d8c78310ba29ccc30e5d09ec9728f0
This commit is contained in:
Colin Cross 2016-11-04 18:24:35 +00:00 committed by android-build-merger
commit 25dabdeb81
1 changed files with 13 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import sys
def perform_find(mindepth, prune, dirlist, filenames):
result = []
pruneleaves = set(map(lambda x: os.path.split(x)[1], prune))
seen = set()
for rootdir in dirlist:
rootdepth = rootdir.count("/")
for root, dirs, files in os.walk(rootdir, followlinks=True):
@ -52,6 +53,18 @@ def perform_find(mindepth, prune, dirlist, filenames):
if filename in files:
result.append(os.path.join(root, filename))
del dirs[:]
# filter out inodes that have already been seen due to symlink loops
i = 0
while i < len(dirs):
st = os.stat(os.path.join(root, dirs[i]))
key = (st.st_dev, st.st_ino)
if key in seen:
del dirs[i]
else:
i += 1
seen.add(key)
return result
def usage():