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. ........ ................
This commit is contained in:
parent
b5ea027cb5
commit
7dfcef577e
|
@ -1554,6 +1554,7 @@ class TarFile(object):
|
|||
self.inodes = {} # dictionary caching the inodes of
|
||||
# archive members already added
|
||||
|
||||
try:
|
||||
if self.mode == "r":
|
||||
self.firstmember = None
|
||||
self.firstmember = self.next()
|
||||
|
@ -1575,6 +1576,11 @@ class TarFile(object):
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue