Skip to content

Commit 79ae967

Browse files
committed
Issue python#12885: Revert commits in 3.4 branch which is security-only fixes.
1 parent 6f5d3fd commit 79ae967

File tree

3 files changed

+29
-69
lines changed

3 files changed

+29
-69
lines changed

Lib/distutils/filelist.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import os, re
88
import fnmatch
9-
import functools
109
from distutils.util import convert_path
1110
from distutils.errors import DistutilsTemplateError, DistutilsInternalError
1211
from distutils import log
@@ -243,28 +242,35 @@ def exclude_pattern (self, pattern,
243242
# ----------------------------------------------------------------------
244243
# Utility functions
245244

246-
def _find_all_simple(path):
247-
"""
248-
Find all files under 'path'
249-
"""
250-
results = (
251-
os.path.join(base, file)
252-
for base, dirs, files in os.walk(path, followlinks=True)
253-
for file in files
254-
)
255-
return filter(os.path.isfile, results)
256-
257-
258245
def findall(dir=os.curdir):
246+
"""Find all files under 'dir' and return the list of full filenames
247+
(relative to 'dir').
259248
"""
260-
Find all files under 'dir' and return the list of full filenames.
261-
Unless dir is '.', return full filenames with dir prepended.
262-
"""
263-
files = _find_all_simple(dir)
264-
if dir == os.curdir:
265-
make_rel = functools.partial(os.path.relpath, start=dir)
266-
files = map(make_rel, files)
267-
return list(files)
249+
from stat import ST_MODE, S_ISREG, S_ISDIR, S_ISLNK
250+
251+
list = []
252+
stack = [dir]
253+
pop = stack.pop
254+
push = stack.append
255+
256+
while stack:
257+
dir = pop()
258+
names = os.listdir(dir)
259+
260+
for name in names:
261+
if dir != os.curdir: # avoid the dreaded "./" syndrome
262+
fullname = os.path.join(dir, name)
263+
else:
264+
fullname = name
265+
266+
# Avoid excess stat calls -- just one will do, thank you!
267+
stat = os.stat(fullname)
268+
mode = stat[ST_MODE]
269+
if S_ISREG(mode):
270+
list.append(fullname)
271+
elif S_ISDIR(mode) and not S_ISLNK(mode):
272+
push(fullname)
273+
return list
268274

269275

270276
def glob_to_re(pattern):

Lib/distutils/tests/test_filelist.py

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from distutils.log import WARN
77
from distutils.errors import DistutilsTemplateError
88
from distutils.filelist import glob_to_re, translate_pattern, FileList
9-
from distutils import filelist
109

11-
import test.support
12-
from test.support import captured_stdout, run_unittest
10+
from test.support import captured_stdout
1311
from distutils.tests import support
1412

1513
MANIFEST_IN = """\
@@ -294,47 +292,5 @@ def test_process_template(self):
294292
self.assertWarnings()
295293

296294

297-
class FindAllTestCase(unittest.TestCase):
298-
@test.support.skip_unless_symlink
299-
def test_missing_symlink(self):
300-
with test.support.temp_cwd():
301-
os.symlink('foo', 'bar')
302-
self.assertEqual(filelist.findall(), [])
303-
304-
def test_basic_discovery(self):
305-
"""
306-
When findall is called with no parameters or with
307-
'.' as the parameter, the dot should be omitted from
308-
the results.
309-
"""
310-
with test.support.temp_cwd():
311-
os.mkdir('foo')
312-
file1 = os.path.join('foo', 'file1.txt')
313-
test.support.create_empty_file(file1)
314-
os.mkdir('bar')
315-
file2 = os.path.join('bar', 'file2.txt')
316-
test.support.create_empty_file(file2)
317-
expected = [file2, file1]
318-
self.assertEqual(sorted(filelist.findall()), expected)
319-
320-
def test_non_local_discovery(self):
321-
"""
322-
When findall is called with another path, the full
323-
path name should be returned.
324-
"""
325-
with test.support.temp_dir() as temp_dir:
326-
file1 = os.path.join(temp_dir, 'file1.txt')
327-
test.support.create_empty_file(file1)
328-
expected = [file1]
329-
self.assertEqual(filelist.findall(temp_dir), expected)
330-
331-
332-
def test_suite():
333-
return unittest.TestSuite([
334-
unittest.makeSuite(FileListTestCase),
335-
unittest.makeSuite(FindAllTestCase),
336-
])
337-
338-
339295
if __name__ == "__main__":
340-
run_unittest(test_suite())
296+
unittest.main()

Misc/NEWS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Core and Builtins
1313
Library
1414
-------
1515

16-
- Issue #12885: Fix error when distutils encounters symlink.
17-
1816
- In the curses module, raise an error if window.getstr() or window.instr() is
1917
passed a negative value.
2018

0 commit comments

Comments
 (0)