mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
[3.12] gh-114959: tarfile: do not ignore errors when extract a directory on top of a file (GH-114960) (GH-114963)
Also, add tests common to tarfile and zipfile.
(cherry picked from commit 96bce033c4
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
c86a9e662f
commit
8ed20bc8bb
5 changed files with 220 additions and 1 deletions
|
@ -15,6 +15,7 @@ import unittest
|
|||
import unittest.mock
|
||||
import tarfile
|
||||
|
||||
from test import archiver_tests
|
||||
from test import support
|
||||
from test.support import os_helper
|
||||
from test.support import script_helper
|
||||
|
@ -4089,6 +4090,38 @@ class TestExtractionFilters(unittest.TestCase):
|
|||
self.expect_exception(TypeError) # errorlevel is not int
|
||||
|
||||
|
||||
class OverwriteTests(archiver_tests.OverwriteTests, unittest.TestCase):
|
||||
testdir = os.path.join(TEMPDIR, "testoverwrite")
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
p = cls.ar_with_file = os.path.join(TEMPDIR, 'tar-with-file.tar')
|
||||
cls.addClassCleanup(os_helper.unlink, p)
|
||||
with tarfile.open(p, 'w') as tar:
|
||||
t = tarfile.TarInfo('test')
|
||||
t.size = 10
|
||||
tar.addfile(t, io.BytesIO(b'newcontent'))
|
||||
|
||||
p = cls.ar_with_dir = os.path.join(TEMPDIR, 'tar-with-dir.tar')
|
||||
cls.addClassCleanup(os_helper.unlink, p)
|
||||
with tarfile.open(p, 'w') as tar:
|
||||
tar.addfile(tar.gettarinfo(os.curdir, 'test'))
|
||||
|
||||
p = os.path.join(TEMPDIR, 'tar-with-implicit-dir.tar')
|
||||
cls.ar_with_implicit_dir = p
|
||||
cls.addClassCleanup(os_helper.unlink, p)
|
||||
with tarfile.open(p, 'w') as tar:
|
||||
t = tarfile.TarInfo('test/file')
|
||||
t.size = 10
|
||||
tar.addfile(t, io.BytesIO(b'newcontent'))
|
||||
|
||||
def open(self, path):
|
||||
return tarfile.open(path, 'r')
|
||||
|
||||
def extractall(self, ar):
|
||||
ar.extractall(self.testdir, filter='fully_trusted')
|
||||
|
||||
|
||||
def setUpModule():
|
||||
os_helper.unlink(TEMPDIR)
|
||||
os.makedirs(TEMPDIR)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue