fixing extraction of multivolume with multiple files
authorEduardo Robles Elvira <edulix@wadobo.com>
Thu, 20 Jun 2013 07:41:56 +0000 (09:41 +0200)
committerEduardo Robles Elvira <edulix@wadobo.com>
Thu, 20 Jun 2013 07:41:56 +0000 (09:41 +0200)
deltatar/tarfile.py
testing/test_multivol.py

index a195fee..72e9d8e 100644 (file)
@@ -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
index 71982a9..6ace811 100644 (file)
@@ -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