mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 17:57:59 +00:00
export-tar: test strip-components and hardlinks for partial export
This commit is contained in:
parent
293324810b
commit
042a4b960b
2 changed files with 51 additions and 7 deletions
|
@ -772,7 +772,7 @@ def do_export_tar(self, args, repository, manifest, key, archive):
|
||||||
rc = filterproc.wait()
|
rc = filterproc.wait()
|
||||||
if rc:
|
if rc:
|
||||||
logger.error('--tar-filter exited with code %d, output file is likely unusable!', rc)
|
logger.error('--tar-filter exited with code %d, output file is likely unusable!', rc)
|
||||||
self.exit_code = set_ec(EXIT_ERROR)
|
self.exit_code = EXIT_ERROR
|
||||||
else:
|
else:
|
||||||
logger.debug('filter exited with code %d', rc)
|
logger.debug('filter exited with code %d', rc)
|
||||||
|
|
||||||
|
|
|
@ -728,7 +728,9 @@ def _extract_hardlinks_setup(self):
|
||||||
self.cmd('init', '--encryption=repokey', self.repository_location)
|
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||||
self.cmd('create', self.repository_location + '::test', 'input')
|
self.cmd('create', self.repository_location + '::test', 'input')
|
||||||
|
|
||||||
@pytest.mark.skipif(not are_hardlinks_supported(), reason='hardlinks not supported')
|
requires_hardlinks = pytest.mark.skipif(not are_hardlinks_supported(), reason='hardlinks not supported')
|
||||||
|
|
||||||
|
@requires_hardlinks
|
||||||
def test_strip_components_links(self):
|
def test_strip_components_links(self):
|
||||||
self._extract_hardlinks_setup()
|
self._extract_hardlinks_setup()
|
||||||
with changedir('output'):
|
with changedir('output'):
|
||||||
|
@ -741,7 +743,7 @@ def test_strip_components_links(self):
|
||||||
self.cmd('extract', self.repository_location + '::test')
|
self.cmd('extract', self.repository_location + '::test')
|
||||||
assert os.stat('input/dir1/hardlink').st_nlink == 4
|
assert os.stat('input/dir1/hardlink').st_nlink == 4
|
||||||
|
|
||||||
@pytest.mark.skipif(not are_hardlinks_supported(), reason='hardlinks not supported')
|
@requires_hardlinks
|
||||||
def test_extract_hardlinks(self):
|
def test_extract_hardlinks(self):
|
||||||
self._extract_hardlinks_setup()
|
self._extract_hardlinks_setup()
|
||||||
with changedir('output'):
|
with changedir('output'):
|
||||||
|
@ -2386,10 +2388,10 @@ def test_export_tar(self):
|
||||||
os.unlink('input/flagfile')
|
os.unlink('input/flagfile')
|
||||||
self.cmd('init', '--encryption=repokey', self.repository_location)
|
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||||
self.cmd('create', self.repository_location + '::test', 'input')
|
self.cmd('create', self.repository_location + '::test', 'input')
|
||||||
self.cmd('export-tar', self.repository_location + '::test', 'simple.tar')
|
self.cmd('export-tar', self.repository_location + '::test', 'simple.tar', '--progress')
|
||||||
with changedir('output'):
|
with changedir('output'):
|
||||||
# This probably assumes GNU tar. Note -p switch to extract permissions regardless of umask.
|
# This probably assumes GNU tar. Note -p switch to extract permissions regardless of umask.
|
||||||
subprocess.check_output(['tar', 'xpf', '../simple.tar'])
|
subprocess.check_call(['tar', 'xpf', '../simple.tar'])
|
||||||
self.assert_dirs_equal('input', 'output/input', ignore_bsdflags=True, ignore_xattrs=True, ignore_ns=True)
|
self.assert_dirs_equal('input', 'output/input', ignore_bsdflags=True, ignore_xattrs=True, ignore_ns=True)
|
||||||
|
|
||||||
@requires_gnutar
|
@requires_gnutar
|
||||||
|
@ -2401,11 +2403,53 @@ def test_export_tar_gz(self):
|
||||||
os.unlink('input/flagfile')
|
os.unlink('input/flagfile')
|
||||||
self.cmd('init', '--encryption=repokey', self.repository_location)
|
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||||
self.cmd('create', self.repository_location + '::test', 'input')
|
self.cmd('create', self.repository_location + '::test', 'input')
|
||||||
self.cmd('export-tar', self.repository_location + '::test', 'simple.tar.gz')
|
list = self.cmd('export-tar', self.repository_location + '::test', 'simple.tar.gz', '--list')
|
||||||
|
assert 'input/file1\n' in list
|
||||||
|
assert 'input/dir2\n' in list
|
||||||
with changedir('output'):
|
with changedir('output'):
|
||||||
subprocess.check_output(['tar', 'xpf', '../simple.tar.gz'])
|
subprocess.check_call(['tar', 'xpf', '../simple.tar.gz'])
|
||||||
self.assert_dirs_equal('input', 'output/input', ignore_bsdflags=True, ignore_xattrs=True, ignore_ns=True)
|
self.assert_dirs_equal('input', 'output/input', ignore_bsdflags=True, ignore_xattrs=True, ignore_ns=True)
|
||||||
|
|
||||||
|
@requires_gnutar
|
||||||
|
def test_export_tar_strip_components(self):
|
||||||
|
if not shutil.which('gzip'):
|
||||||
|
pytest.skip('gzip is not installed')
|
||||||
|
self.create_test_files()
|
||||||
|
os.unlink('input/flagfile')
|
||||||
|
self.cmd('init', '--encryption=repokey', self.repository_location)
|
||||||
|
self.cmd('create', self.repository_location + '::test', 'input')
|
||||||
|
list = self.cmd('export-tar', self.repository_location + '::test', 'simple.tar', '--strip-components=1', '--list')
|
||||||
|
# --list's path are those before processing with --strip-components
|
||||||
|
assert 'input/file1\n' in list
|
||||||
|
assert 'input/dir2\n' in list
|
||||||
|
with changedir('output'):
|
||||||
|
subprocess.check_call(['tar', 'xpf', '../simple.tar'])
|
||||||
|
self.assert_dirs_equal('input', 'output/', ignore_bsdflags=True, ignore_xattrs=True, ignore_ns=True)
|
||||||
|
|
||||||
|
@requires_hardlinks
|
||||||
|
@requires_gnutar
|
||||||
|
def test_export_tar_strip_components_links(self):
|
||||||
|
self._extract_hardlinks_setup()
|
||||||
|
self.cmd('export-tar', self.repository_location + '::test', 'output.tar', '--strip-components=2')
|
||||||
|
with changedir('output'):
|
||||||
|
subprocess.check_call(['tar', 'xpf', '../output.tar'])
|
||||||
|
assert os.stat('hardlink').st_nlink == 2
|
||||||
|
assert os.stat('subdir/hardlink').st_nlink == 2
|
||||||
|
assert os.stat('aaaa').st_nlink == 2
|
||||||
|
assert os.stat('source2').st_nlink == 2
|
||||||
|
|
||||||
|
@requires_hardlinks
|
||||||
|
@requires_gnutar
|
||||||
|
def test_extract_hardlinks(self):
|
||||||
|
self._extract_hardlinks_setup()
|
||||||
|
self.cmd('export-tar', self.repository_location + '::test', 'output.tar', 'input/dir1')
|
||||||
|
with changedir('output'):
|
||||||
|
subprocess.check_call(['tar', 'xpf', '../output.tar'])
|
||||||
|
assert os.stat('input/dir1/hardlink').st_nlink == 2
|
||||||
|
assert os.stat('input/dir1/subdir/hardlink').st_nlink == 2
|
||||||
|
assert os.stat('input/dir1/aaaa').st_nlink == 2
|
||||||
|
assert os.stat('input/dir1/source2').st_nlink == 2
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless('binary' in BORG_EXES, 'no borg.exe available')
|
@unittest.skipUnless('binary' in BORG_EXES, 'no borg.exe available')
|
||||||
class ArchiverTestCaseBinary(ArchiverTestCase):
|
class ArchiverTestCaseBinary(ArchiverTestCase):
|
||||||
|
|
Loading…
Reference in a new issue