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
Title: zipfile.extractall always raises an OSError after successfully unzipping all files
Type: behavior Stage:
Components: Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, amaury.forgeotdarc, aymill, ezio.melotti, terytkon, ysj.ray
Priority: normal Keywords:

Created on 2010-07-05 18:37 by aymill, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
example_1.zip aymill, 2010-07-05 18:37 WinZip 11.1, unencrypted.
Messages (6)
msg109346 - (view) Author: Andrew Miller (aymill) Date: 2010-07-05 18:37
Tried it with a variety of unencrypted zips. Zipped with WinZip 11.1. Looks like it tries to unzip a second time after it completes the first unzip.

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from zipfile import ZipFile
>>> zip = ZipFile("example_1.zip")
>>> zip.extractall()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/zipfile.py", line 935, in extractall
    self.extract(zipinfo, path, pwd)
  File "/usr/lib/python2.6/zipfile.py", line 923, in extract
    return self._extract_member(member, path, pwd)
  File "/usr/lib/python2.6/zipfile.py", line 960, in _extract_member
    os.mkdir(targetpath)
OSError: [Errno 17] File exists: '/home/andy/projects/codedropvalidator/testdata/example'
>>>
msg111551 - (view) Author: Teemu Rytkönen (terytkon) Date: 2010-07-25 18:34
Hi!
I encountered the same problem and I debugged it a bit..
I think it not doing the entire unzipping again, but the problem is that the winzip packaged zip actually contains all file and directory entries and it fails trying to create already existing directory (because the dir has been created for the files that are in it).

I tried a quick and dirty fix for the zipfile _extract_member method, which basically should fix the problem! 

So here I create the directory only if it is not already existing, to get those empty directories created inside the zip.

zipfile:
959:        if member.filename[-1] == '/':
<add>           if not os.path.isdir(targetpath):
960:                os.mkdir(targetpath)
msg111815 - (view) Author: ysj.ray (ysj.ray) Date: 2010-07-28 14:40
I didn't see this problem in py2.7 and py3k on debian linux. Is this windows specific or this bug has been fixed since py2.7?
msg111902 - (view) Author: Teemu Rytkönen (terytkon) Date: 2010-07-29 09:18
Hi!

I haven't tested this in linux or with python 2.7 so can't say for sure.. 

However I would assume that the main issue is with the zipdate it self (So does it have those empty directories, which at least winzip creates) and then about how does the os.mkdir act with when trying to create already existing folder.

Did you try it with the example_1.zip, which has those folders described in the zip centralrecord??

Should I also try it out with linux?

-Teemu
msg111906 - (view) Author: ysj.ray (ysj.ray) Date: 2010-07-29 10:00
I found that this issue is duplicate with issue6050. And the bug has been fixed since 2.6.3.

So this issue should be closed.
msg111927 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-29 14:00
Closed as duplicate of issue6050.
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53418
2010-07-29 14:00:49BreamoreBoysetstatus: open -> closed

nosy: + BreamoreBoy
messages: + msg111927

resolution: duplicate
2010-07-29 10:00:21ysj.raysetmessages: + msg111906
2010-07-29 09:18:44terytkonsetmessages: + msg111902
2010-07-28 14:40:41ysj.raysetnosy: + ysj.ray
messages: + msg111815
2010-07-27 22:35:44pitrousetnosy: + amaury.forgeotdarc, ezio.melotti

versions: + Python 3.1, Python 2.7, Python 3.2
2010-07-25 18:34:13terytkonsetnosy: + terytkon

messages: + msg111551
versions: + Python 2.6
2010-07-05 18:37:10aymillcreate