reinit crypto for objects other than files
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Tue, 21 Mar 2017 14:20:44 +0000 (15:20 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:08 +0000 (13:34 +0200)
Invoke the new-item handler to force a new crypto object for
directories and anything else as well.

deltatar/tarfile.py

index 74f15e6..4cc2840 100644 (file)
@@ -2552,21 +2552,6 @@ class TarFile(object):
         else:
             _size_left = lambda: tarinfo.size
 
-        # If there's no data to follow, finish
-        if not fileobj:
-            if self.save_to_members:
-                self.members.append(tarinfo)
-            return
-
-        target_size_left = _size_left()
-        source_size_left = tarinfo.size
-        assert tarinfo.volume_offset == 0
-
-        # we only split volumes in the middle of a file, that means we have
-        # to write at least one block
-        if target_size_left < BLOCKSIZE:
-            target_size_left = BLOCKSIZE
-
         # below attributes aren’t present with other compression methods
         init_e = getattr (self.fileobj, "_init_write_encrypt", None)
         init_c = getattr (self.fileobj, "_init_write_gz"     , None)
@@ -2583,6 +2568,22 @@ class TarFile(object):
             if init_e is not None: init_e (tarinfo.name)
             if init_c is not None: init_c ()
 
+        # If there's no data to follow, finish
+        if not fileobj:
+            new_item_hook ()
+            if self.save_to_members:
+                self.members.append(tarinfo)
+            return
+
+        target_size_left = _size_left()
+        source_size_left = tarinfo.size
+        assert tarinfo.volume_offset == 0
+
+        # we only split volumes in the middle of a file, that means we have
+        # to write at least one block
+        if target_size_left < BLOCKSIZE:
+            target_size_left = BLOCKSIZE
+
         # loop over multiple volumes
         while source_size_left > 0: