summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-11-26 07:22:28 (GMT)
committerGeorg Brandl <georg@python.org>2010-11-26 07:22:28 (GMT)
commit86e0c89b2a9c715939a7d7aee3dc271850eabd62 (patch)
tree679d9a26ebfcd4e116851b7ec709bf013c874d92 /Lib/zipfile.py
parent420cca92e8b1b5b9bd2b9a58a93d4e8f0ff86d1d (diff)
downloadcpython-86e0c89b2a9c715939a7d7aee3dc271850eabd62.zip
cpython-86e0c89b2a9c715939a7d7aee3dc271850eabd62.tar.gz
cpython-86e0c89b2a9c715939a7d7aee3dc271850eabd62.tar.bz2
Merged revisions 85455 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85455 | georg.brandl | 2010-10-14 08:59:45 +0200 (Do, 14 Okt 2010) | 1 line #1710703: write zipfile structures also in the case of closing a new, but empty, archive. ........
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 496cf83..7e3caf0 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -158,7 +158,13 @@ def _EndRecData64(fpin, offset, endrec):
"""
Read the ZIP64 end-of-archive records and use that to update endrec
"""
- fpin.seek(offset - sizeEndCentDir64Locator, 2)
+ try:
+ fpin.seek(offset - sizeEndCentDir64Locator, 2)
+ except IOError:
+ # If the seek fails, the file is not large enough to contain a ZIP64
+ # end-of-archive record, so just return the end record we were given.
+ return endrec
+
data = fpin.read(sizeEndCentDir64Locator)
sig, diskno, reloff, disks = struct.unpack(structEndArchive64Locator, data)
if sig != stringEndArchive64Locator:
@@ -705,14 +711,22 @@ class ZipFile:
if key == 'r':
self._GetContents()
elif key == 'w':
- pass
+ # set the modified flag so central directory gets written
+ # even if no files are added to the archive
+ self._didModify = True
elif key == 'a':
- try: # See if file is a zip file
+ try:
+ # See if file is a zip file
self._RealGetContents()
# seek to start of directory and overwrite
self.fp.seek(self.start_dir, 0)
- except BadZipfile: # file is not a zip file, just append
+ except BadZipfile:
+ # file is not a zip file, just append
self.fp.seek(0, 2)
+
+ # set the modified flag so central directory gets written
+ # even if no files are added to the archive
+ self._didModify = True
else:
if not self._filePassed:
self.fp.close()
@@ -739,7 +753,10 @@ class ZipFile:
def _RealGetContents(self):
"""Read in the table of contents for the ZIP file."""
fp = self.fp
- endrec = _EndRecData(fp)
+ try:
+ endrec = _EndRecData(fp)
+ except IOError:
+ raise BadZipfile("File is not a zip file")
if not endrec:
raise BadZipfile, "File is not a zip file"
if self.debug > 1: