diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2016-09-02 03:27:45 (GMT) |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-09-02 03:27:45 (GMT) |
| commit | 79ae9671ff3db55da376af8ce2e56e6bf2b95c2b (patch) | |
| tree | d4eb062ef602bcd182b016e7f41f952728fed623 /Lib/distutils/filelist.py | |
| parent | 6f5d3fd4d1c8cc575951ace5894428d0c2901eb6 (diff) | |
| download | cpython-79ae9671ff3db55da376af8ce2e56e6bf2b95c2b.zip cpython-79ae9671ff3db55da376af8ce2e56e6bf2b95c2b.tar.gz cpython-79ae9671ff3db55da376af8ce2e56e6bf2b95c2b.tar.bz2 | |
Issue #12885: Revert commits in 3.4 branch which is security-only fixes.
Diffstat (limited to 'Lib/distutils/filelist.py')
| -rw-r--r-- | Lib/distutils/filelist.py | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py index 6522e69..db3f7a9 100644 --- a/Lib/distutils/filelist.py +++ b/Lib/distutils/filelist.py @@ -6,7 +6,6 @@ and building lists of files. import os, re import fnmatch -import functools from distutils.util import convert_path from distutils.errors import DistutilsTemplateError, DistutilsInternalError from distutils import log @@ -243,28 +242,35 @@ class FileList: # ---------------------------------------------------------------------- # Utility functions -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) - - def findall(dir=os.curdir): + """Find all files under 'dir' and return the list of full filenames + (relative to 'dir'). """ - Find all files under 'dir' and return the list of full filenames. - Unless dir is '.', return full filenames with dir prepended. - """ - files = _find_all_simple(dir) - if dir == os.curdir: - make_rel = functools.partial(os.path.relpath, start=dir) - files = map(make_rel, files) - return list(files) + from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK + + list = [] + stack = [dir] + pop = stack.pop + push = stack.append + + while stack: + dir = pop() + names = os.listdir(dir) + + for name in names: + if dir != os.curdir: # avoid the dreaded "./" syndrome + fullname = os.path.join(dir, name) + else: + fullname = name + + # Avoid excess stat calls -- just one will do, thank you! + stat = os.stat(fullname) + mode = stat[ST_MODE] + if S_ISREG(mode): + list.append(fullname) + elif S_ISDIR(mode) and not S_ISLNK(mode): + push(fullname) + return list def glob_to_re(pattern): |
