]> granicus.if.org Git - python/commitdiff
Flush bz2 data even if nothing had been written so far. Fixes #1013882.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 22 Aug 2004 21:28:33 +0000 (21:28 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 22 Aug 2004 21:28:33 +0000 (21:28 +0000)
Will backport to 2.3.

Lib/tarfile.py
Lib/test/test_tarfile.py

index ff9f51f2651f67871e183b17aaa09cff975c39a0..2d5bf642aef611bf4c508eeba8f2c217638d7448 100644 (file)
@@ -350,9 +350,9 @@ class _Stream:
         if self.closed:
             return
 
+        if self.mode == "w" and self.type != "tar":
+            self.buf += self.cmp.flush()
         if self.mode == "w" and self.buf:
-            if self.type != "tar":
-                self.buf += self.cmp.flush()
             self.fileobj.write(self.buf)
             self.buf = ""
             if self.type == "gz":
index 52b62048da2171b010cde47e9f8659645695bf21..66156023f7448873441cc86fea0af6ce63490731 100644 (file)
@@ -177,7 +177,8 @@ class WriteTest(BaseTest):
     def setUp(self):
         mode = self.mode + self.sep + self.comp
         self.src = tarfile.open(tarname(self.comp), 'r')
-        self.dst = tarfile.open(tmpname(), mode)
+        self.dstname = tmpname()
+        self.dst = tarfile.open(self.dstname, mode)
 
     def tearDown(self):
         self.src.close()
@@ -191,6 +192,11 @@ class WriteTest(BaseTest):
         self.dst.posix = 0
         self._test()
 
+    def test_small(self):
+        self.dst.add(os.path.join(os.path.dirname(__file__),"cfgparser.1"))
+        self.dst.close()
+        self.assertNotEqual(os.stat(self.dstname).st_size, 0)
+
     def _test(self):
         for tarinfo in self.src:
             if not tarinfo.isreg():