From: Philipp Gesang Date: Thu, 20 Apr 2017 09:34:35 +0000 (+0200) Subject: fix compression handling on volume bounds X-Git-Tag: v2.2~7^2~162 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=170c6c5224907e676b9000b60755c4d0bdc748d8;p=python-delta-tar fix compression handling on volume bounds 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. --- 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!