Skip to content

Commit e926a95

Browse files
committed
1 parent 72673e0 commit e926a95

File tree

2 files changed

+1
-67
lines changed

2 files changed

+1
-67
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,64 +2020,9 @@ def test_repack_prepended_bytes(self):
20202020
fh.write(b'dummy ')
20212021
fh.write(fz.read())
20222022
with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
2023-
self.assertEqual(zh.data_offset, 6)
20242023
for i in ii:
20252024
zh.remove(self.test_files[i][0])
20262025
zh.repack()
2027-
if hasattr(zh, 'data_offset'):
2028-
self.assertEqual(zh.data_offset, 6)
2029-
2030-
# check infolist
2031-
self.assertEqual(
2032-
[ComparableZipInfo(zi) for zi in zh.infolist()],
2033-
[ComparableZipInfo(zi) for zi in expected_zinfos],
2034-
)
2035-
2036-
# check file size
2037-
self.assertEqual(os.path.getsize(TESTFN), expected_size)
2038-
2039-
# make sure the zip file is still valid
2040-
with zipfile.ZipFile(TESTFN) as zh:
2041-
self.assertIsNone(zh.testzip())
2042-
2043-
def test_repack_prepended_file_entry(self):
2044-
for ii in ([0], [0, 1], [0, 1, 2]):
2045-
with self.subTest(remove=ii):
2046-
# calculate the expected results
2047-
fz = io.BytesIO()
2048-
test_files = [data for j, data in enumerate(self.test_files) if j not in ii]
2049-
self._prepare_zip_from_test_files(fz, test_files)
2050-
fz.seek(0)
2051-
with open(TESTFN, 'wb') as fh:
2052-
fh.write(b'dummy ')
2053-
fh.write(fz.read())
2054-
with zipfile.ZipFile(TESTFN) as zh:
2055-
expected_zinfos = list(zh.infolist())
2056-
expected_size = os.path.getsize(TESTFN)
2057-
2058-
# do the removal and check the result
2059-
fz = io.BytesIO()
2060-
with zipfile.ZipFile(fz, 'w') as zh:
2061-
for j, (file, data) in enumerate(self.test_files):
2062-
if j in ii:
2063-
zh.writestr(file, data)
2064-
fz.seek(0)
2065-
prefix = fz.read()
2066-
2067-
fz = io.BytesIO()
2068-
test_files = [data for j, data in enumerate(self.test_files) if j not in ii]
2069-
self._prepare_zip_from_test_files(fz, test_files)
2070-
fz.seek(0)
2071-
2072-
with open(TESTFN, 'wb') as fh:
2073-
fh.write(b'dummy ')
2074-
fh.write(prefix)
2075-
fh.write(fz.read())
2076-
2077-
with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
2078-
self.assertEqual(zh.data_offset, 6 + len(prefix))
2079-
zh.repack()
2080-
self.assertEqual(zh.data_offset, 6)
20812026

20822027
# check infolist
20832028
self.assertEqual(
@@ -2267,10 +2212,8 @@ def test_repack_removed_prepended_bytes(self):
22672212
fh.write(b'dummy ')
22682213
fh.write(fz.read())
22692214
with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
2270-
self.assertEqual(zh.data_offset, 6)
22712215
zinfos = [zh.remove(self.test_files[i][0]) for i in ii]
22722216
zh.repack(zinfos)
2273-
self.assertEqual(zh.data_offset, 6)
22742217

22752218
# check infolist
22762219
self.assertEqual(

Lib/zipfile/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,8 +1453,7 @@ def repack(self, zfile, removed=None):
14531453
14541454
Side effects:
14551455
- Modifies the ZIP file in place.
1456-
- Updates zfile.start_dir and zfile.data_offset to account for
1457-
removed data.
1456+
- Updates zfile.start_dir to account for removed data.
14581457
- Sets zfile._didModify to True.
14591458
- Updates header_offset and clears _end_offset of referenced
14601459
ZipInfo instances.
@@ -1559,14 +1558,6 @@ def repack(self, zfile, removed=None):
15591558
zfile.start_dir -= entry_offset
15601559
zfile._didModify = True
15611560

1562-
if zfile._data_offset:
1563-
try:
1564-
offset = filelist[0].header_offset
1565-
except IndexError:
1566-
offset = zfile.start_dir
1567-
if offset < zfile._data_offset:
1568-
zfile._data_offset = offset
1569-
15701561
for zinfo in filelist:
15711562
zinfo._end_offset = None
15721563

0 commit comments

Comments
 (0)