findleaves.py: prevent recursion into symlink loops
am: 7829ebfebd
Change-Id: Ib0ff185e2798ca57c6c28157a1182e7b4d1ed820
This commit is contained in:
commit
7227637308
|
@ -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():
|
||||
|
|
Loading…
Reference in New Issue