assert os.path.exists("big")
assert hash == self.md5sum("big")
+ def test_volume_not_found(self):
+ '''
+ Create a tar file with multiple volumes and one file and extract it, but
+ one of the volumes is missing
+ '''
+ # create the content of the file to compress and hash it
+ hash = self.create_file("big", 5*1024*1024)
+
+ # create the tar file with volumes
+ tarobj = TarFile.open("sample.tar",
+ mode="w",
+ format=self.tarfile_format,
+ max_volume_size=2*1024*1024,
+ new_volume_handler=new_volume_handler)
+ tarobj.add("big")
+ tarobj.close()
+
+ # check that the tar volumes were correctly created
+ assert os.path.exists("sample.tar")
+ assert os.path.exists("sample.tar.1")
+ assert os.path.exists("sample.tar.2")
+ assert not os.path.exists("sample.tar.3")
+
+ os.unlink("big")
+ os.unlink("sample.tar.2")
+
+ class VolumeNotFound(Exception):
+ pass
+
+ def new_volume_handler2(tarobj, base_name, volume_number):
+ '''
+ Handles the new volumes
+ '''
+ volume_path = "%s.%d" % (base_name, volume_number)
+
+ try:
+ tarobj.open_volume(volume_path)
+ except IOError as e:
+ # only volume number 2 is missing
+ assert volume_number == 2
+ raise e
+
+ # extract and check output
+ tarobj = TarFile.open("sample.tar",
+ mode="r",
+ new_volume_handler=new_volume_handler2)
+ try:
+ tarobj.extractall()
+ except IOError as e:
+ pass
+ tarobj.close()
+ assert os.path.exists("big")
+ assert hash != self.md5sum("big")
+
+
class MultivolPaxFormatTest(MultivolGnuFormatTest):
"""
Test multivolume support in tarfile with PAX format