diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-04-04 18:56:49 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-04-04 18:56:49 (GMT) |
commit | 7d3bad66e4b32fa65fce219661b16d75e90c152f (patch) | |
tree | 20b242735b0cac4324c18e4a159d00b5638a8414 /Lib/zipfile.py | |
parent | 42fc7ccdac459a5a37cba83e4585611e7e7fdb86 (diff) | |
download | cpython-7d3bad66e4b32fa65fce219661b16d75e90c152f.zip cpython-7d3bad66e4b32fa65fce219661b16d75e90c152f.tar.gz cpython-7d3bad66e4b32fa65fce219661b16d75e90c152f.tar.bz2 |
Sf bug [ #412214 ] ZipFile constructor leaves files open.
This applies the patch Fred Drake created to fix it.
I'm checking it in since I had to apply the patch anyway in order
to test its behavior on Windows.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index b638592..5dedc1b 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -186,9 +186,23 @@ class ZipFile: else: # file is not a zip file, just append fp.seek(0, 2) else: + if not self._filePassed: + self.fp.close() + self.fp = None raise RuntimeError, 'Mode must be "r", "w" or "a"' def _GetContents(self): + """Read the directory, making sure we close the file if the format + is bad.""" + try: + self._RealGetContents() + except BadZipfile: + if not self._filePassed: + self.fp.close() + self.fp = None + raise + + def _RealGetContents(self): """Read in the table of contents for the ZIP file.""" fp = self.fp fp.seek(-22, 2) # Start of end-of-archive record |