diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-02-03 18:18:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-03 16:18:46 +0000 |
commit | 96bce033c4a4da7112792ba335ef3eb9a3eb0da0 (patch) | |
tree | 7d34b0e90ac63c13e60beddbc5df6c8e1ae94f4e /Lib/test/test_tarfile.py | |
parent | b4240fd68ecd2c22ec82ac549eabfe5fd35fab2a (diff) | |
download | cpython-96bce033c4a4da7112792ba335ef3eb9a3eb0da0.tar.gz cpython-96bce033c4a4da7112792ba335ef3eb9a3eb0da0.zip |
gh-114959: tarfile: do not ignore errors when extract a directory on top of a file (GH-114960)
Also, add tests common to tarfile and zipfile.
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r-- | Lib/test/test_tarfile.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index da5009126b3..51f070e9604 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -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 @@ -4135,6 +4136,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) |