8000 Work around Path.glob() failure in 3.10 · python/cpython@dff62a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit dff62a1

Browse files
committed
Work around Path.glob() failure in 3.10
1 parent bf6b637 commit dff62a1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Lib/test/test_tarfile.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3338,7 +3338,7 @@ class TestExtractionFilters(unittest.TestCase):
33383338
destdir = outerdir / 'dest'
33393339

33403340
@contextmanager
3341-
def check_context(self, tar, filter, *, check_flag=True):
3341+
def check_context(self, tar, filter, *, check_flag=True, ignored_trees=()):
33423342
"""Extracts `tar` to `self.destdir` and allows checking the result
33433343
33443344
If an error occurs, it must be checked using `expect_exception`
@@ -3351,6 +3351,10 @@ def check_context(self, tar, filter, *, check_flag=True):
33513351
A file called 'flag' is made in outerdir (i.e. outside destdir)
33523352
before extraction; it should not be altered nor should its contents
33533353
be read/copied.
3354+
3355+
*ignored_trees* is a set of directories to remove (including their
3356+
contents) right after the archive is extracted. It is a workaround
3357+
for Path.glob() failing to get all files in Python 3.10 and below.
33543358
"""
33553359
with os_helper.temp_dir(self.outerdir):
33563360
flag_path = self.outerdir / 'flag'
@@ -3362,6 +3366,8 @@ def check_context(self, tar, filter, *, check_flag=True):
33623366
self.reraise_exception = True
33633367
self.expected_paths = set()
33643368
else:
3369+
for ignored_tree in ignored_trees:
3370+
os_helper.rmtree((self.destdir / ignored_tree).resolve())
33653371
self.raised_exception = None
33663372
self.reraise_exception = False
33673373
self.expected_paths = set(self.outerdir.glob('**/*'))
@@ -3573,15 +3579,14 @@ def test_realpath_limit_attack(self):
35733579

35743580
with (self.subTest('fully_trusted'),
35753581
self.check_context(arc.open(), filter='fully_trusted',
3576-
check_flag=False)):
3582+
check_flag=False, ignored_trees={component})):
35773583
if sys.platform == 'win32':
35783584
self.expect_exception((FileNotFoundError, FileExistsError))
35793585
elif self.raised_exception:
35803586
# Cannot symlink/hardlink: tarfile falls back to getmember()
35813587
self.expect_exception(KeyError)
35823588
# Otherwise, this block should never enter.
35833589
else:
3584-
self.expect_any_tree(component)
35853590
self.expect_file('flaglink', content='overwrite')
35863591
self.expect_file('../newfile', content='new')
35873592
self.expect_file('escape', type=tarfile.SYMTYPE)

0 commit comments

Comments
 (0)
0