diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2009-11-18 21:11:27 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2009-11-18 21:11:27 (GMT) |
commit | 7dfcef577e5d713c49322254ab364fcda8fe370a (patch) | |
tree | e4214bb8297f1ad7856c9bdc16149d25766f5f4e /Lib/tarfile.py | |
parent | b5ea027cb533b51d6932806155dcced68ac8b2ec (diff) | |
download | cpython-7dfcef577e5d713c49322254ab364fcda8fe370a.zip cpython-7dfcef577e5d713c49322254ab364fcda8fe370a.tar.gz cpython-7dfcef577e5d713c49322254ab364fcda8fe370a.tar.bz2 |
Merged revisions 76383 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76383 | lars.gustaebel | 2009-11-18 21:29:25 +0100 (Wed, 18 Nov 2009) | 10 lines
Merged revisions 76381 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76381 | lars.gustaebel | 2009-11-18 21:24:54 +0100 (Wed, 18 Nov 2009) | 3 lines
Issue #7341: Close the internal file object in the TarFile
constructor in case of an error.
........
................
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r-- | Lib/tarfile.py | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 3a3d2c9..8eb80f8 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1554,27 +1554,33 @@ class TarFile(object): self.inodes = {} # dictionary caching the inodes of # archive members already added - if self.mode == "r": - self.firstmember = None - self.firstmember = self.next() - - if self.mode == "a": - # Move to the end of the archive, - # before the first empty block. - self.firstmember = None - while True: - if self.next() is None: - if self.offset > 0: - self.fileobj.seek(self.fileobj.tell() - BLOCKSIZE) - break - - if self.mode in "aw": - self._loaded = True - - if self.pax_headers: - buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy()) - self.fileobj.write(buf) - self.offset += len(buf) + try: + if self.mode == "r": + self.firstmember = None + self.firstmember = self.next() + + if self.mode == "a": + # Move to the end of the archive, + # before the first empty block. + self.firstmember = None + while True: + if self.next() is None: + if self.offset > 0: + self.fileobj.seek(self.fileobj.tell() - BLOCKSIZE) + break + + if self.mode in "aw": + self._loaded = True + + if self.pax_headers: + buf = self.tarinfo.create_pax_global_header(self.pax_headers.copy()) + self.fileobj.write(buf) + self.offset += len(buf) + except: + if not self._extfileobj: + self.fileobj.close() + self.closed = True + raise #-------------------------------------------------------------------------- # Below are the classmethods which act as alternate constructors to the |