From 9fbec7ad5e8fcdd9dcc5abd496341b86d12a4472 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 18 Jan 2014 15:53:05 +0200 Subject: [PATCH] Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn't write complete output on close. --- Lib/tarfile.py | 2 +- Lib/test/test_tarfile.py | 6 ++++++ Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) 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. -- 2.40.0