classification
Title: ZipFile don't overwrite compresed files at create
Type: behavior Stage:
Components: Versions:
process
Status: closed Resolution: invalid
Dependencies: Superseder: remove/delete method for zipfile/tarfile objects
View: 6818
Assigned To: Nosy List: amaury.forgeotdarc, piranna, terry.reedy
Priority: normal Keywords:

Created on 2011-03-06 18:24 by piranna, last changed 2011-03-19 05:07 by terry.reedy. This issue is now closed.

Messages (4)
msg130182 - (view) Author: Jesús Leganés Combarro (piranna) Date: 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) Date: 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) Date: 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) Date: 2011-03-19 05:07
2.6 is only open for security fixes.
History
Date User Action Args
2011-03-19 05:07:47terry.reedysetstatus: open -> closed

superseder: remove/delete method for zipfile/tarfile objects
versions: - Python 2.6
nosy: + terry.reedy

messages: + msg131388
resolution: invalid
2011-03-07 13:13:09pirannasetmessages: + msg130255
2011-03-07 12:46:17amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg130254
2011-03-06 18:24:12pirannacreate