From 00c34a12bf24e353a442013831346b5db36ce918 Mon Sep 17 00:00:00 2001 From: Eduardo Robles Elvira Date: Thu, 20 Jun 2013 09:41:56 +0200 Subject: [PATCH] fixing extraction of multivolume with multiple files --- deltatar/tarfile.py | 2 +- testing/test_multivol.py | 46 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index a195fee..72e9d8e 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -1285,7 +1285,7 @@ class TarInfo(object): """ self.offset_data = tarfile.fileobj.tell() offset = self.offset_data - if self.isreg() or self.type not in SUPPORTED_TYPES: + if self.isreg() or self.ismultivol() or self.type not in SUPPORTED_TYPES: # Skip the following data blocks. offset += self._block(self.size) tarfile.offset = offset diff --git a/testing/test_multivol.py b/testing/test_multivol.py index 71982a9..6ace811 100644 --- a/testing/test_multivol.py +++ b/testing/test_multivol.py @@ -122,7 +122,7 @@ class MultivolTest(unittest.TestCase): assert os.path.exists("big") assert hash == self.md5sum("big") - def test_multiple_files_volume(self): + def test_multiple_files_volumes(self): # create the content of the file to compress and hash it # create sample data @@ -251,8 +251,8 @@ class MultivolTest(unittest.TestCase): assert hash == self.md5sum("big") - def test_multiple_files_volume(self): - # create the content of the file to compress and hash it + def test_multiple_files_volumes_extract(self): + # creates a multivolume tar file with multiple files and extracts it # create sample data hash = dict() @@ -289,6 +289,46 @@ class MultivolTest(unittest.TestCase): new_volume_handler=new_volume_handler) tarobj.extractall() tarobj.close() + + for key, value in hash.iteritems(): + assert os.path.exists(key) + assert value == self.md5sum(key) + + def test_multiple_files_extract(self): + # creates a simple tar file with multiple files and extracts it + + # create sample data + hash = dict() + self.create_random_file("big", 50000) + hash["big"] = self.md5sum("big") + self.create_random_file("small", 100) + hash["small"] = self.md5sum("small") + self.create_random_file("small2", 354) + hash["small2"] = self.md5sum("small2") + + # create the tar file with volumes + tarobj = TarFile.open("sample.tar", + mode="w") + tarobj.add("big") + tarobj.add("small") + tarobj.add("small2") + tarobj.close() + + # check that the tar volumes were correctly created + assert os.path.exists("sample.tar") + assert not os.path.exists("sample.tar.1") + + os.unlink("big") + os.unlink("small") + os.unlink("small2") + + # extract and check output + tarobj = TarFile.open("sample.tar", + mode="r", + new_volume_handler=new_volume_handler) + tarobj.extractall() + tarobj.close() + for key, value in hash.iteritems(): assert os.path.exists(key) assert value == self.md5sum(key) \ No newline at end of file -- 1.7.1