mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-40105: ZipFile truncate in append mode with shorter comment (GH-19337)
This commit is contained in:
parent
a195bceff7
commit
ff9147d93b
3 changed files with 7 additions and 0 deletions
|
@ -1856,11 +1856,14 @@ class OtherTests(unittest.TestCase):
|
|||
self.assertEqual(zipf.comment, b"an updated comment")
|
||||
|
||||
# check that comments are correctly shortened in append mode
|
||||
# and the file is indeed truncated
|
||||
with zipfile.ZipFile(TESTFN,mode="w") as zipf:
|
||||
zipf.comment = b"original comment that's longer"
|
||||
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
|
||||
original_zip_size = os.path.getsize(TESTFN)
|
||||
with zipfile.ZipFile(TESTFN,mode="a") as zipf:
|
||||
zipf.comment = b"shorter comment"
|
||||
self.assertTrue(original_zip_size > os.path.getsize(TESTFN))
|
||||
with zipfile.ZipFile(TESTFN,mode="r") as zipf:
|
||||
self.assertEqual(zipf.comment, b"shorter comment")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue