[Python-checkins] cpython (merge 3.3 -> default): Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn't

serhiy.storchaka python-checkins at python.org
Sat Jan 18 14:56:29 CET 2014


http://hg.python.org/cpython/rev/e154b93f3857
changeset:   88546:e154b93f3857
parent:      88544:7a2db897a1b6
parent:      88545:5c69332dc3b0
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat Jan 18 15:53:39 2014 +0200
summary:
  Issue #20238: TarFile opened with external fileobj and "w:gz" mode didn't
write complete output on close.

files:
  Lib/tarfile.py           |  2 +-
  Lib/test/test_tarfile.py |  6 ++++++
  Misc/NEWS                |  3 +++
  3 files changed, 10 insertions(+), 1 deletions(-)


diff --git a/Lib/tarfile.py b/Lib/tarfile.py
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -1618,7 +1618,7 @@
             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
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -857,6 +857,12 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,9 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list