msg121376 - (view) |
Author: Sridhar Ratnakumar (srid) |
Date: 2010-11-17 19:14 |
When extracting a zip file containing deep hierarchy files, `extractall` throws IOError on Windows - perhaps due to limitation in Windows max path length. Ideally it should be throwing an instance of zipfile.ZipError - so that application can handle it reliably. An IOError can mean a wide range of errors, so it is pointless to catch IOError and ignore it. To reproduce, run extractall over http://pypi.python.org/packages/source/c/collective.generic.skel/collective.generic.skel-0.1.0.zip using Python 2.6.6 or Python 2.7 > python -c "import zipfile ; f=zipfile.ZipFile('collective.generic.skel-0.1.0.zip'); f.extractall()" Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\zipfile.py", line 923, in extractall self.extract(zipinfo, path, pwd) File "C:\Python27\lib\zipfile.py", line 911, in extract return self._extract_member(member, path, pwd) File "C:\Python27\lib\zipfile.py", line 955, in _extract_member target = file(targetpath, "wb") IOError: [Errno 2] No such file or directory: 'C:\\Documents and Settings\\apy\\ My Documents\\Downloads\\collective.generic.skel-0.1.0\\src\\collective\\generic \\skel\\skin\\tmpl\\+namespace++ndot++nested_namespace+.+project_name+\\src\\+na mespace+\\+nested_namespace+\\+project_name+\\profiles\\default\\+namespace++ndo t++nested_namespace+.+project_name+_various.txt_tmpl' |
|
|
msg121377 - (view) |
Author: Sridhar Ratnakumar (srid) |
Date: 2010-11-17 19:16 |
It appears that there is no base class (zipfile.ZipError) for zipfile errors. Maybe there should be? At the moment, I do: try: [...] except zipfile.BadZipFile, zipfile.LargeZipFile: [...] .. which is of course unreliable. There is no guarantee that a new exception class will not be added to zipfile (thus necessitating me to change my code). Better to have a single base class - zipfile.ZipError similar to TarError http://docs.python.org/library/tarfile.html#tarfile.TarError |
|
|
msg121389 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2010-11-17 22:47 |
How would you implement this? And would you turn a "disk full" error, for example, into a ZipError as well? |
|
|
msg121390 - (view) |
Author: Sridhar Ratnakumar (srid) |
Date: 2010-11-17 22:56 |
> How would you implement this? And would you turn a "disk full" error, for example, into a ZipError as well? I see your point. I am not sure what a reliable way to do this would be. For the record, this is how I workaround it: https://github.com/ActiveState/applib/blob/master/applib/_compression.py#L78 (I cannot find any other reason for an IOError/errno=2 during extraction) And I, personally, wouldn't turn the disk full error into a ZipError. |
|
|
msg121392 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2010-11-17 23:41 |
I think you did the right thing already. The choice of which errors to catch and which ones to let throw really depends on the usage (what about permission or lock errors? other limitations due to a USB stick? why is "disk full" different? and so on) It's not the Zip module which raises the error here. It's the OS, that's why IMO it should not be a ZipError. |
|
|
msg121460 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2010-11-18 15:11 |
I agree with Amaury. IMO the IOError is the correct error, since it is bubbling up unexpectedly (from zipfile's viewpoint) from a lower layer and is not an error specific to the zip protocol implementation. (CF the discussion surrounding PEP 3151). Probably there should indeed be a common base class for the existing zipfile errors, but that's a feature request. |
|
|