]> granicus.if.org Git - python/commitdiff
Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn't
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 18 Jan 2014 13:53:05 +0000 (15:53 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 18 Jan 2014 13:53:05 +0000 (15:53 +0200)
write complete output on close.

Lib/tarfile.py
Lib/test/test_tarfile.py
Misc/NEWS

index 987c0113626ef5df845c60d7dcde9cc705df68e4..8a69988c086b0bdf029b973873b9ae9e8cbe4ea9 100755 (executable)
@@ -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
index 6986fc00bd68d9d942346538f39fcf7c458935ed..ceaa3aa4949970d1c128cd2eb5b4fbc20a081768 100644 (file)
@@ -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):
index 4e9be22576c68d0269ecdf02f1bf853c321f617e..839e8fe4d8590772348c2a5aa2ff19f48d33d575 100644 (file)
--- 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.