This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: ZipFile don't overwrite compresed files at create
类型: behavior Stage:
Components: Versions:
process
状态: closed Resolution: not a bug
Dependencies: 后续: remove/delete method for zipfile/tarfile objects
View: 6818
分配给: 抄送列表: amaury.forgeotdarc, piranna, terry.reedy
优先级: normal 关键字:

Created on 2011-03-06 18:24 by piranna, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg130182 - (view) Author: Jesús Leganés Combarro (piranna) 日期: 2011-03-06 18:24
I've created a new, compresed ZipFile in memory (using StringIO) and added several files to it with ZipFile.write(), later i've added a new file with the same name of one of the previous ones just to overwrite it with some dinamic data using ZipFile.writestr(), and finally i've closed the StringIO ZipFile and writen to the hard disk.

Secondly, i've opened it with FileRoller and found that the overwritten file is twice inside the ZipFile, the first and the second one, with different sizes and timestamp. Luckily, extracting one of them just get only the more recent one, but the fact is that the old one is already there and it's listed instead being overwritten with the last, new one, and i don't know if it's a bug (i think so) or just a feature.
msg130254 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) 日期: 2011-03-07 12:46
> Luckily, extracting one of them just get only the more recent one

It's not only luck: a Zip file has a "central directory" used to retrieve data. ZipFile just appends the new file data to the end of the Zip file, then write the updated directory structure.

Removing the old content is another matter, and is similar to issue6818.
This requires a whole copy of the zip file, and so far, no acceptable patch was proposed.
msg130255 - (view) Author: Jesús Leganés Combarro (piranna) 日期: 2011-03-07 13:13
Ok, they talk about remove it, that's why i didn't found it :-P Ok, it make sense. By the way, this way the old data is available? How? (Just to know... it could be a courious feature :-D )
msg131388 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) 日期: 2011-03-19 05:07
2.6 is only open for security fixes.
历史
日期 用户 动作 参数
2022-04-11 14:57:14admin修改github: 55624
2011-03-19 05:07:47terry.reedy修改状态: open -> closed

后续: remove/delete method for zipfile/tarfile objects
versions: - Python 2.6
抄送: + terry.reedy

消息: + msg131388
resolution: not a bug
2011-03-07 13:13:09piranna修改消息: + msg130255
2011-03-07 12:46:17amaury.forgeotdarc修改抄送: + amaury.forgeotdarc
消息: + msg130254
2011-03-06 18:24:12piranna创建