|
@@ -5,10 +5,10 @@ import stat
|
|
|
import sys
|
|
|
import shutil
|
|
|
import tempfile
|
|
|
-from darc import xattr
|
|
|
-from darc.archiver import Archiver
|
|
|
-from darc.repository import Repository
|
|
|
-from darc.testsuite import DarcTestCase
|
|
|
+from attic import xattr
|
|
|
+from attic.archiver import Archiver
|
|
|
+from attic.repository import Repository
|
|
|
+from attic.testsuite import AtticTestCase
|
|
|
|
|
|
has_mtime_ns = sys.version >= '3.3'
|
|
|
utime_supports_fd = os.utime in getattr(os, 'supports_fd', {})
|
|
@@ -27,7 +27,7 @@ class changedir:
|
|
|
os.chdir(self.old)
|
|
|
|
|
|
|
|
|
-class ArchiverTestCase(DarcTestCase):
|
|
|
+class ArchiverTestCase(AtticTestCase):
|
|
|
|
|
|
prefix = ''
|
|
|
|
|
@@ -40,8 +40,8 @@ class ArchiverTestCase(DarcTestCase):
|
|
|
self.output_path = os.path.join(self.tmpdir, 'output')
|
|
|
self.keys_path = os.path.join(self.tmpdir, 'keys')
|
|
|
self.cache_path = os.path.join(self.tmpdir, 'cache')
|
|
|
- os.environ['DARC_KEYS_DIR'] = self.keys_path
|
|
|
- os.environ['DARC_CACHE_DIR'] = self.cache_path
|
|
|
+ os.environ['ATTIC_KEYS_DIR'] = self.keys_path
|
|
|
+ os.environ['ATTIC_CACHE_DIR'] = self.cache_path
|
|
|
os.mkdir(self.input_path)
|
|
|
os.mkdir(self.output_path)
|
|
|
os.mkdir(self.keys_path)
|
|
@@ -53,7 +53,7 @@ class ArchiverTestCase(DarcTestCase):
|
|
|
shutil.rmtree(self.tmpdir)
|
|
|
os.chdir(self._old_wd)
|
|
|
|
|
|
- def darc(self, *args, **kwargs):
|
|
|
+ def attic(self, *args, **kwargs):
|
|
|
exit_code = kwargs.get('exit_code', 0)
|
|
|
args = list(args)
|
|
|
try:
|
|
@@ -70,8 +70,8 @@ class ArchiverTestCase(DarcTestCase):
|
|
|
sys.stdout, sys.stderr = stdout, stderr
|
|
|
|
|
|
def create_src_archive(self, name):
|
|
|
- self.darc('init', self.repository_location)
|
|
|
- self.darc('create', self.repository_location + '::' + name, src_dir)
|
|
|
+ self.attic('init', self.repository_location)
|
|
|
+ self.attic('create', self.repository_location + '::' + name, src_dir)
|
|
|
|
|
|
def create_regual_file(self, name, size=0):
|
|
|
filename = os.path.join(self.input_path, name)
|
|
@@ -132,91 +132,91 @@ class ArchiverTestCase(DarcTestCase):
|
|
|
os.symlink('somewhere', os.path.join(self.input_path, 'link1'))
|
|
|
# FIFO node
|
|
|
os.mkfifo(os.path.join(self.input_path, 'fifo1'))
|
|
|
- self.darc('init', self.repository_location)
|
|
|
- self.darc('create', self.repository_location + '::test', 'input')
|
|
|
- self.darc('create', self.repository_location + '::test.2', 'input')
|
|
|
+ self.attic('init', self.repository_location)
|
|
|
+ self.attic('create', self.repository_location + '::test', 'input')
|
|
|
+ self.attic('create', self.repository_location + '::test.2', 'input')
|
|
|
with changedir('output'):
|
|
|
- self.darc('extract', self.repository_location + '::test')
|
|
|
- self.assert_equal(len(self.darc('list', self.repository_location).splitlines()), 2)
|
|
|
- self.assert_equal(len(self.darc('list', self.repository_location + '::test').splitlines()), 9)
|
|
|
+ self.attic('extract', self.repository_location + '::test')
|
|
|
+ self.assert_equal(len(self.attic('list', self.repository_location).splitlines()), 2)
|
|
|
+ self.assert_equal(len(self.attic('list', self.repository_location + '::test').splitlines()), 9)
|
|
|
self.diff_dirs('input', 'output/input')
|
|
|
- info_output = self.darc('info', self.repository_location + '::test')
|
|
|
+ info_output = self.attic('info', self.repository_location + '::test')
|
|
|
shutil.rmtree(self.cache_path)
|
|
|
- info_output2 = self.darc('info', self.repository_location + '::test')
|
|
|
+ info_output2 = self.attic('info', self.repository_location + '::test')
|
|
|
# info_output2 starts with some "initializing cache" text but should
|
|
|
# end the same way as info_output
|
|
|
assert info_output2.endswith(info_output)
|
|
|
|
|
|
def test_extract_include_exclude(self):
|
|
|
- self.darc('init', self.repository_location)
|
|
|
+ self.attic('init', self.repository_location)
|
|
|
self.create_regual_file('file1', size=1024 * 80)
|
|
|
self.create_regual_file('file2', size=1024 * 80)
|
|
|
self.create_regual_file('file3', size=1024 * 80)
|
|
|
self.create_regual_file('file4', size=1024 * 80)
|
|
|
- self.darc('create', '--exclude=input/file4', self.repository_location + '::test', 'input')
|
|
|
+ self.attic('create', '--exclude=input/file4', self.repository_location + '::test', 'input')
|
|
|
with changedir('output'):
|
|
|
- self.darc('extract', self.repository_location + '::test', 'input/file1', )
|
|
|
+ self.attic('extract', self.repository_location + '::test', 'input/file1', )
|
|
|
self.assert_equal(sorted(os.listdir('output/input')), ['file1'])
|
|
|
with changedir('output'):
|
|
|
- self.darc('extract', '--exclude=input/file2', self.repository_location + '::test')
|
|
|
+ self.attic('extract', '--exclude=input/file2', self.repository_location + '::test')
|
|
|
self.assert_equal(sorted(os.listdir('output/input')), ['file1', 'file3'])
|
|
|
|
|
|
def test_overwrite(self):
|
|
|
self.create_regual_file('file1', size=1024 * 80)
|
|
|
self.create_regual_file('dir2/file2', size=1024 * 80)
|
|
|
- self.darc('init', self.repository_location)
|
|
|
- self.darc('create', self.repository_location + '::test', 'input')
|
|
|
+ self.attic('init', self.repository_location)
|
|
|
+ self.attic('create', self.repository_location + '::test', 'input')
|
|
|
# Overwriting regular files and directories should be supported
|
|
|
os.mkdir('output/input')
|
|
|
os.mkdir('output/input/file1')
|
|
|
os.mkdir('output/input/dir2')
|
|
|
with changedir('output'):
|
|
|
- self.darc('extract', self.repository_location + '::test')
|
|
|
+ self.attic('extract', self.repository_location + '::test')
|
|
|
self.diff_dirs('input', 'output/input')
|
|
|
# But non-empty dirs should fail
|
|
|
os.unlink('output/input/file1')
|
|
|
os.mkdir('output/input/file1')
|
|
|
os.mkdir('output/input/file1/dir')
|
|
|
with changedir('output'):
|
|
|
- self.darc('extract', self.repository_location + '::test', exit_code=1)
|
|
|
+ self.attic('extract', self.repository_location + '::test', exit_code=1)
|
|
|
|
|
|
def test_delete(self):
|
|
|
self.create_regual_file('file1', size=1024 * 80)
|
|
|
self.create_regual_file('dir2/file2', size=1024 * 80)
|
|
|
- self.darc('init', self.repository_location)
|
|
|
- self.darc('create', self.repository_location + '::test', 'input')
|
|
|
- self.darc('create', self.repository_location + '::test.2', 'input')
|
|
|
- self.darc('verify', self.repository_location + '::test')
|
|
|
- self.darc('verify', self.repository_location + '::test.2')
|
|
|
- self.darc('delete', self.repository_location + '::test')
|
|
|
- self.darc('verify', self.repository_location + '::test.2')
|
|
|
- self.darc('delete', self.repository_location + '::test.2')
|
|
|
+ self.attic('init', self.repository_location)
|
|
|
+ self.attic('create', self.repository_location + '::test', 'input')
|
|
|
+ self.attic('create', self.repository_location + '::test.2', 'input')
|
|
|
+ self.attic('verify', self.repository_location + '::test')
|
|
|
+ self.attic('verify', self.repository_location + '::test.2')
|
|
|
+ self.attic('delete', self.repository_location + '::test')
|
|
|
+ self.attic('verify', self.repository_location + '::test.2')
|
|
|
+ self.attic('delete', self.repository_location + '::test.2')
|
|
|
# Make sure all data except the manifest has been deleted
|
|
|
repository = Repository(self.repository_path)
|
|
|
self.assert_equal(repository._len(), 1)
|
|
|
|
|
|
def test_corrupted_repository(self):
|
|
|
self.create_src_archive('test')
|
|
|
- self.darc('verify', self.repository_location + '::test')
|
|
|
+ self.attic('verify', self.repository_location + '::test')
|
|
|
name = sorted(os.listdir(os.path.join(self.tmpdir, 'repository', 'data', '0')), reverse=True)[0]
|
|
|
fd = open(os.path.join(self.tmpdir, 'repository', 'data', '0', name), 'r+')
|
|
|
fd.seek(100)
|
|
|
fd.write('X')
|
|
|
fd.close()
|
|
|
- self.darc('verify', self.repository_location + '::test', exit_code=1)
|
|
|
+ self.attic('verify', self.repository_location + '::test', exit_code=1)
|
|
|
|
|
|
def test_prune_repository(self):
|
|
|
- self.darc('init', self.repository_location)
|
|
|
- self.darc('create', self.repository_location + '::test1', src_dir)
|
|
|
- self.darc('create', self.repository_location + '::test2', src_dir)
|
|
|
- self.darc('prune', self.repository_location, '--daily=2')
|
|
|
- output = self.darc('list', self.repository_location)
|
|
|
+ self.attic('init', self.repository_location)
|
|
|
+ self.attic('create', self.repository_location + '::test1', src_dir)
|
|
|
+ self.attic('create', self.repository_location + '::test2', src_dir)
|
|
|
+ self.attic('prune', self.repository_location, '--daily=2')
|
|
|
+ output = self.attic('list', self.repository_location)
|
|
|
assert 'test1' not in output
|
|
|
assert 'test2' in output
|
|
|
|
|
|
def test_usage(self):
|
|
|
- self.assert_raises(SystemExit, lambda: self.darc())
|
|
|
- self.assert_raises(SystemExit, lambda: self.darc('-h'))
|
|
|
+ self.assert_raises(SystemExit, lambda: self.attic())
|
|
|
+ self.assert_raises(SystemExit, lambda: self.attic('-h'))
|
|
|
|
|
|
|
|
|
class RemoteArchiverTestCase(ArchiverTestCase):
|