fix compression handling on volume bounds
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 20 Apr 2017 09:34:35 +0000 (11:34 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
The old “concat compression” simply relied on the _Stream() ctor
to create a new zip block which is no longer possible since the
prerequisite encryption is only available when the first object
is committed to the archive.

Hence, reintroduce the new block initialization after
transitioning to the new volume.

deltatar/tarfile.py

index 5b8c2fa..a2d21c4 100644 (file)
@@ -512,12 +512,6 @@ class _Stream:
     def __del__(self):
         if hasattr(self, "closed") and not self.closed:
             self.close()
-        #if self.encryption is not None:
-        #    print("crypto: %s"
-        #          % (self.encryption.currentstate () == crypto.STATE_DEAD
-        #                    and "inactive" or "active"))
-        #    print("crypto: %d objects handled, %d B in, %d B out"
-        #          % self.encryption.counters ())
 
 
     def _init_write_encrypt (self, entry=None):
@@ -2452,9 +2446,6 @@ class TarFile(object):
            You can create TarInfo objects using gettarinfo().
            On Windows platforms, `fileobj' should always be opened with mode
            'rb' to avoid irritation about the file size.
-
-           Encryption restarts with each volume. Compression restarts with each
-           file and may span volumes.
         """
         self._check("aw")
 
@@ -2520,7 +2511,7 @@ class TarFile(object):
                 # another one; otherwise, the encryption must include the block
                 # padding below.
                 if getattr (self.fileobj, "encryption", None) is not None:
-                    self.fileobj._finalize_write_encrypt ()
+                    self.fileobj.close (close_fileobj=True)
 
                 tarinfo.type = GNUTYPE_MULTIVOL
 
@@ -2546,6 +2537,8 @@ class TarFile(object):
 
                 if getattr (self.fileobj, "encryption", None) is not None:
                     self.fileobj._init_write_encrypt (tarinfo.name)
+                if self.concat_compression:
+                    self.fileobj.new_compression_block()
 
                 # write new volume header
                 buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
@@ -2568,7 +2561,7 @@ class TarFile(object):
         if self.save_to_members:
             self.members.append(tarinfo)
 
-    def open_volume(self, name="", fileobj=None):
+    def open_volume(self, name="", fileobj=None, encryption=None):
         '''
         Called by the user to change this tar file to point to a new volume.
         '''
@@ -2587,7 +2580,7 @@ class TarFile(object):
                             comptype=self.fileobj.comptype,
                             fileobj=None,
                             bufsize=self.fileobj.bufsize,
-                            encryption=self.encryption,
+                            encryption=encryption,
                             concat_stream=self.fileobj.concat_stream)
             else:
                 # here, we lose information about compression/encryption!