properly handle encryption and compression of empty archives
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Tue, 2 May 2017 15:59:19 +0000 (17:59 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
The old implementation always initialized in the ctor regardless
of whether contents would be written to the archive. For empty
archives this now has to be done in ``.close()`` if no data has
been added yet.

deltatar/tarfile.py

index 6e7517d..3d91e43 100644 (file)
@@ -2221,12 +2221,16 @@ class TarFile(object):
 
     def close(self):
         """Close the TarFile. In write-mode, two finishing zero blocks are
-           appended to the archive.
+           appended to the archive. A special case are empty archives which are
+           initialized accordingly so the two mandatory blocks of zeros are
+           written abiding by the requested encryption and compression settings.
         """
         if self.closed:
             return
 
         if self.mode in "aw":
+            if self.arcmode & ARCMODE_CONCAT and self.fileobj.tell () == 0:
+                self.fileobj.next ("")
             self.fileobj.write(NUL * (BLOCKSIZE * 2))
             self.offset += (BLOCKSIZE * 2)
             # fill up the end with zero-blocks