From: Philipp Gesang Date: Tue, 25 Apr 2017 14:38:12 +0000 (+0200) Subject: handle uncompressed, encrypted archives with tarfile X-Git-Tag: v2.2~7^2~144 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=200d4866f134f8bded6a9eaa688907b602c67b56;p=python-delta-tar handle uncompressed, encrypted archives with tarfile Internally, tarfile.py uses “tar” to refer to uncompressed archives, so just handle this accordingly at the API level. --- diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 21027d0..7e8ef9c 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -499,13 +499,13 @@ class _Stream: else: self.cmp = lzma.LZMACompressor() - elif comptype not in [ "tar" ]: + elif comptype != "tar": if self.encryption is not None: raise InvalidEncryptionError("encryption not available for " "compression %s" % comptype) raise CompressionError("unknown compression type %r" % comptype) - except: # XXX seriously? + except: if not self._extfileobj: self.fileobj.close() self.closed = True @@ -2028,7 +2028,8 @@ class TarFile(object): stream = _Stream(name, filemode, comptype, fileobj, bufsize, concat_stream=True, encryption=encryption, compresslevel=compresslevel) - kwargs ["concat_compression"] = True + if comptype != "tar": + kwargs ["concat_compression"] = True try: t = cls(name, filemode, stream, **kwargs) except: # XXX except what? diff --git a/testing/test_multivol.py b/testing/test_multivol.py index c99f521..934bd6f 100644 --- a/testing/test_multivol.py +++ b/testing/test_multivol.py @@ -18,6 +18,7 @@ import os from tempfile import TemporaryDirectory +import deltatar.crypto as crypto from deltatar.tarfile import TarFile, PAX_FORMAT, GNU_FORMAT, BLOCKSIZE from . import BaseTest, new_volume_handler, closing_new_volume_handler from .create_pseudo_random_files import create_file as create_random_file @@ -172,7 +173,9 @@ class MultivolGnuFormatTest(BaseTest): assert value == self.md5sum(key) def test_get_file_size(self): - ''' test _Stream.get_file_size which is basis for multivol with compres + ''' + Test _Stream.get_file_size which is the basis for multivol with + compression. ''' # create test files of different sizes @@ -191,15 +194,21 @@ class MultivolGnuFormatTest(BaseTest): max_err = 0 max_err_post = 0 - for mode in 'w|gz', 'w|bz2', 'w|xz', 'w#gz', 'w#gz.aes128', \ - 'w#gz.aes256', 'w#aes128': + for mode, password in [ ('w|gz', None) , ('w|bz2', None) + , ('w|xz', None) , ('w#gz' , None) + , ('w#gz', "test"), ('w#tar', "test") + ]: tar_file_name = "size_test.tar." + mode[2:] for size_number in range(4,n_sizes): for order in 1,-1: # small files first or big files first + encryptor = None + if password is not None: + encryptor = crypto.Encrypt (password=password, version=1, + paramversion=1) tarobj = TarFile.open(tar_file_name, mode=mode, format=self.tarfile_format, - password='test') + encryption=encryptor) for file_name in file_names[:size_number][::order]: tarobj.add(file_name) estimate = tarobj.fileobj.estim_file_size()