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
class MultivolGnuFormatTest(BaseTest):
"""
assert os.path.exists("big")
assert hash == self.md5sum("big")
+ def test_multivol_compress(self):
+ ''' check creation of multiple volumes when compression is on '''
+
+ # create a random file that is not so easy to compress...
+ filename = create_random_file('./', 100000)
+ hash = self.md5sum(filename)
+
+ # need own volume handler so files maintain their suffix for gunzip
+ def my_volume_handler(tarobj, base_name, volume_number):
+ if not base_name.endswith('.tar.gz'):
+ raise ValueError('need .tar.gz file!')
+ tarobj.fileobj.close()
+ new_name = '{}.{}.tar.gz'.format(base_name[:-7], volume_number)
+ tarobj.open_volume(new_name)
+
+ # create the tar file with volumes and compression
+ tarobj = TarFile.open("sample.tar.gz",
+ mode="w#gz",
+ format=self.tarfile_format,
+ max_volume_size=30000,
+ new_volume_handler=my_volume_handler,
+ debug=3)
+ tarobj.add(filename)
+ tarobj.list()
+ tarobj.close()
+
+ # data fits into 2 volumes -- check that no third is created
+ assert os.path.exists("sample.tar.gz")
+ assert os.path.exists("sample.1.tar.gz")
+ assert not os.path.exists("sample.tar.gz.1")
+ assert not os.path.exists("sample.tar.gz.2")
+ assert not os.path.exists("sample.2.tar.gz.2")
+
+ os.unlink(filename)
+ assert not os.path.exists(filename)
+
+ # extract with shell means; slightly complicated because the linux
+ # tar/gunzip cannot do gzipped-multi-volume archives
+ print('unpacking:')
+ import subprocess
+ for cmd in 'gunzip -v sample.tar.gz', 'gunzip -v sample.1.tar.gz', \
+ 'tar xvfM sample.tar --file=sample.1.tar':
+ print(cmd)
+ output = subprocess.check_output(cmd.split(),
+ universal_newlines=True)
+ for line in output.splitlines():
+ print(line.rstrip())
+ assert os.path.exists(filename)
+ assert hash == self.md5sum(filename)
+
+ os.unlink('sample.tar')
+ os.unlink('sample.1.tar')
+
def test_volume_extract1(self):
'''
Create a tar file with multiple volumes and one file and extract it