mirror of
https://github.com/python/cpython.git
synced 2026-02-14 03:10:44 +00:00
Issue #7341: Close the internal file object in the TarFile
constructor in case of an error.
This commit is contained in:
parent
c029942ea0
commit
355538e5f5
2 changed files with 27 additions and 18 deletions
|
|
@ -1557,27 +1557,33 @@ def __init__(self, name=None, mode="r", fileobj=None, format=None,
|
|||
self.inodes = {} # dictionary caching the inodes of
|
||||
# archive members already added
|
||||
|
||||
if self.mode == "r":
|
||||
self.firstmember = None
|
||||
self.firstmember = self.next()
|
||||
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(- BLOCKSIZE, 1)
|
||||
break
|
||||
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(- BLOCKSIZE, 1)
|
||||
break
|
||||
|
||||
if self.mode in "aw":
|
||||
self._loaded = True
|
||||
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)
|
||||
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
|
||||
|
||||
def _getposix(self):
|
||||
return self.format == USTAR_FORMAT
|
||||
|
|
|
|||
|
|
@ -440,6 +440,9 @@ Core and Builtins
|
|||
Library
|
||||
-------
|
||||
|
||||
- Issue #7341: Close the internal file object in the TarFile constructor in
|
||||
case of an error.
|
||||
|
||||
- Issue #7293: distutils.test_msvc9compiler is fixed to work on any fresh
|
||||
Windows box. Help provided by David Bolen.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue