-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid infinite loops with symlinks #2707
Conversation
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be submitted to https://github.com/pypa/distutils first.
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a regression test for this change?
As upstream pypa/distutils#44 is a very new project with a single maintainer and not really tested workflows (see its lack of CI jobs), I think we should aim to fix this here fist as it fixing a 6 years old bug which I consider critical, infinite loops. |
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
See #2714, where I'm integrating the changes based on the report/PR in distutils. If these changes are needed for Setuptools separately from distutils (i.e. while Setuptools still falls back to stdlib distutils), let's use the implementation from distutils. |
Fixes: #332
Summary of changes
Closes
Pull Request Checklist
changelog.d/
.(See documentation for details)