Skip to content

Commit

Permalink
Avoid infinite loops with symlinks
Browse files Browse the repository at this point in the history
Fixes: pypa#332
  • Loading branch information
ssbarnea committed Jun 23, 2021
1 parent 2234e88 commit 94afb2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
22 changes: 16 additions & 6 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,22 @@ def _find_all_simple(path):
"""
Find all files under 'path'
"""
results = (
os.path.join(base, file)
for base, dirs, files in os.walk(path, followlinks=True)
for file in files
)
return filter(os.path.isfile, results)
# https://bugs.python.org/issue44497
dirs = set()
files = set()
for dirpath, dirnames, filenames in os.walk(path, followlinks=True):
st = os.stat(dirpath)
scandirs = []
for dirname in dirnames:
st = os.stat(os.path.join(dirpath, dirname))
dirkey = st.st_dev, st.st_ino
if dirkey not in dirs:
dirs.add(dirkey)
scandirs.append(dirname)
dirnames[:] = scandirs
for f in filenames:
files.add(os.path.join(dirpath, f))
return files


def findall(dir=os.curdir):
Expand Down
22 changes: 16 additions & 6 deletions setuptools/_distutils/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,22 @@ def _find_all_simple(path):
"""
Find all files under 'path'
"""
results = (
os.path.join(base, file)
for base, dirs, files in os.walk(path, followlinks=True)
for file in files
)
return filter(os.path.isfile, results)
# https://bugs.python.org/issue44497
dirs = set()
files = set()
for dirpath, dirnames, filenames in os.walk(path, followlinks=True):
st = os.stat(dirpath)
scandirs = []
for dirname in dirnames:
st = os.stat(os.path.join(dirpath, dirname))
dirkey = st.st_dev, st.st_ino
if dirkey not in dirs:
dirs.add(dirkey)
scandirs.append(dirname)
dirnames[:] = scandirs
for f in filenames:
files.add(os.path.join(dirpath, f))
return files


def findall(dir=os.curdir):
Expand Down

0 comments on commit 94afb2d

Please sign in to comment.