From 170c6c5224907e676b9000b60755c4d0bdc748d8 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 20 Apr 2017 11:34:35 +0200 Subject: [PATCH] fix compression handling on volume bounds MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 17 +++++------------ 1 files changed, 5 insertions(+), 12 deletions(-) diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 5b8c2fa..a2d21c4 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -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! -- 1.7.1