# Create nonexistent files in append mode.
self.mode = "w"
self._mode = "wb"
- fileobj = bltn_open(name, self._mode)
self._extfileobj = False
+
+ if isinstance(self.fileobj, _Stream):
+ fileobj = _Stream(name=name,
+ mode=self.fileobj.mode,
+ comptype=self.fileobj.comptype,
+ fileobj=None,
+ bufsize=self.fileobj.bufsize,
+ concat_stream=self.fileobj.concat_stream)
+ else:
+ fileobj = bltn_open(name, self._mode)
else:
if name is None and hasattr(fileobj, "name"):
name = fileobj.name
import os, unittest, hashlib, string
import random
+def new_volume_handler(tarobj, base_name, volume_number):
+ '''
+ Handles the new volumes
+ '''
+ volume_path = "%s.%d" % (base_name, volume_number)
+ tarobj.open_volume(volume_path)
+
class BaseTest(unittest.TestCase):
"""
Test concatenated compression in tarfiles
'''
Remove temporal files created by unit tests
'''
- os.system("rm -rf big small small2 sample.*")
+ os.system("rm -rf big big2 small small2 sample.*")
def create_file(self, path, length):
'''
with open(filename,'rb') as f:
for chunk in iter(lambda: f.read(128*md5.block_size), b''):
md5.update(chunk)
- return md5.hexdigest()
\ No newline at end of file
+ return md5.hexdigest()
from deltatar.tarfile import TarFile, GNU_FORMAT
import filesplit
-from . import BaseTest
+from . import BaseTest, new_volume_handler
class ConcatCompressTest(BaseTest):
"""
assert os.path.exists(key)
assert value == self.md5sum(key)
+ def test_multivol_gzip_concat_extract(self):
+ '''
+ Test multivol tarball with concat compression.
+ '''
+
+ # create sample data
+ hash = dict()
+ hash["big"] = self.create_file("big", 50000)
+ hash["big2"] = self.create_file("big2", 10200)
+ hash["small"] = self.create_file("small", 100)
+ hash["small2"] = self.create_file("small2", 354)
+
+ # create the tar file with volumes
+ tarobj = TarFile.open("sample.tar.gz",
+ mode="w#gz",
+ concat_compression=True,
+ max_volume_size=20000,
+ new_volume_handler=new_volume_handler)
+ tarobj.add("big")
+ tarobj.add("big2")
+ tarobj.add("small")
+ tarobj.add("small2")
+ tarobj.close()
+
+ assert os.path.exists("sample.tar.gz")
+ os.unlink("big")
+ os.unlink("big2")
+ os.unlink("small")
+ os.unlink("small2")
+
+ # extract
+ tarobj = TarFile.open("sample.tar.gz",
+ mode="r#gz",
+ new_volume_handler=new_volume_handler)
+ tarobj.extractall()
+ tarobj.close()
+
+ # check output
+ for key, value in hash.iteritems():
+ assert os.path.exists(key)
+ assert value == self.md5sum(key)
+
def test_multiple_files_rescue_extract(self):
'''
Use filesplit utility to split the file in compressed tar blocks that
import os, unittest, hashlib, string
from deltatar.tarfile import TarFile, PAX_FORMAT, GNU_FORMAT, BLOCKSIZE
-from . import BaseTest
-
-def new_volume_handler(tarobj, base_name, volume_number):
- '''
- Handles the new volumes
- '''
- volume_path = "%s.%d" % (base_name, volume_number)
- tarobj.open_volume(volume_path)
-
+from . import BaseTest, new_volume_handler
class MultivolGnuFormatTest(BaseTest):
"""