From: Serhiy Storchaka Date: Sat, 18 Jan 2014 13:53:05 +0000 (+0200) Subject: Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn't X-Git-Tag: v3.3.4rc1~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fbec7ad5e8fcdd9dcc5abd496341b86d12a4472;p=python Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn't write complete output on close. --- diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 987c011362..8a69988c08 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -1642,7 +1642,7 @@ class TarFile(object): if not extfileobj and fileobj is not None: fileobj.close() raise - t._extfileobj = extfileobj + t._extfileobj = False return t @classmethod diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 6986fc00bd..ceaa3aa494 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -855,6 +855,12 @@ class WriteTestBase(TarTest): tar.addfile(tarfile.TarInfo("foo")) tar.close() self.assertFalse(fobj.closed, "external fileobjs must never closed") + # Issue #20238: Incomplete gzip output with mode="w:gz" + data = fobj.getvalue() + del tar + support.gc_collect() + self.assertFalse(fobj.closed) + self.assertEqual(data, fobj.getvalue()) class WriteTest(WriteTestBase, unittest.TestCase): diff --git a/Misc/NEWS b/Misc/NEWS index 4e9be22576..839e8fe4d8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -43,6 +43,9 @@ Core and Builtins Library ------- +- Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn't + write complete output on close. + - Issue #20245: The open functions in the tarfile module now correctly handle empty mode.