mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Try to fix test_tarfile issues on Windows buildbots by closing file
objects explicitly instead of letting them linger on.
This commit is contained in:
parent
e5768cf348
commit
95f5560b46
2 changed files with 388 additions and 293 deletions
|
@ -1764,14 +1764,19 @@ class TarFile(object):
|
||||||
|
|
||||||
if fileobj is None:
|
if fileobj is None:
|
||||||
fileobj = bltn_open(name, mode + "b")
|
fileobj = bltn_open(name, mode + "b")
|
||||||
|
extfileobj = False
|
||||||
|
else:
|
||||||
|
extfileobj = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t = cls.taropen(name, mode,
|
t = cls.taropen(name, mode,
|
||||||
gzip.GzipFile(name, mode, compresslevel, fileobj),
|
gzip.GzipFile(name, mode, compresslevel, fileobj),
|
||||||
**kwargs)
|
**kwargs)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
if not extfileobj:
|
||||||
|
fileobj.close()
|
||||||
raise ReadError("not a gzip file")
|
raise ReadError("not a gzip file")
|
||||||
t._extfileobj = False
|
t._extfileobj = extfileobj
|
||||||
return t
|
return t
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -1795,6 +1800,7 @@ class TarFile(object):
|
||||||
try:
|
try:
|
||||||
t = cls.taropen(name, mode, fileobj, **kwargs)
|
t = cls.taropen(name, mode, fileobj, **kwargs)
|
||||||
except (IOError, EOFError):
|
except (IOError, EOFError):
|
||||||
|
fileobj.close()
|
||||||
raise ReadError("not a bzip2 file")
|
raise ReadError("not a bzip2 file")
|
||||||
t._extfileobj = False
|
t._extfileobj = False
|
||||||
return t
|
return t
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue