1
0
mirror of https://github.com/gryf/fs-uae-wrapper.git synced 2025-12-18 20:10:26 +01:00

Fixed issue with compressing files with tar.*

This changeset fixes tar behavior on creating archive, like:

  tar cf foo.tar .

which include also archive file itself, so that tar reports an error
`file changed as we read it` during appending archive file to itself.

This changest is fixing that by replacing dot with list of items to be
added to the archive (similar as in RarArchive.create).
This commit is contained in:
2017-01-06 16:53:49 +01:00
parent 250b1c4c2c
commit 77cf10cee7
3 changed files with 39 additions and 18 deletions

View File

@@ -53,6 +53,15 @@ class TarArchive(Archive):
EXTRACT = ['xf']
ARCH = 'tar'
def create(self, arch_name, files=None):
files = files if files else sorted(os.listdir('.'))
result = subprocess.call([self._compess] + self.ADD + [arch_name] +
files)
if result != 0:
sys.stderr.write("Unable to create archive `%s'\n" % arch_name)
return False
return True
class TarGzipArchive(TarArchive):
ADD = ['zcf']

View File

@@ -7,7 +7,7 @@ from distutils.core import setup
setup(name='fs-uae-wrapper',
packages=['fs_uae_wrapper'],
version='0.5',
version='0.6',
description='Automate archives and state for fs-uae',
author='Roman Dobosz',
author_email='gryf73@gmail.com',

View File

@@ -60,61 +60,73 @@ class TestArchive(TestCase):
self.assertFalse(arch.extract('foo'))
call.assert_called_once_with(['false', 'x', 'foo'])
@mock.patch('os.path.exists')
@mock.patch('fs_uae_wrapper.path.which')
@mock.patch('subprocess.call')
def test_tar(self, call, which):
def test_tar(self, call, which, exists):
with open('foo', 'w') as fobj:
fobj.write('\n')
which.return_value = 'tar'
exists.return_value = True
arch = file_archive.TarArchive()
arch.archiver = 'tar'
call.return_value = 0
self.assertTrue(arch.create('foo'))
call.assert_called_once_with(['tar', 'cf', 'foo', '.'])
self.assertTrue(arch.create('foo.tar'))
call.assert_called_once_with(['tar', 'cf', 'foo.tar', 'foo'])
call.reset_mock()
call.return_value = 1
self.assertFalse(arch.extract('foo'))
call.assert_called_once_with(['tar', 'xf', 'foo'])
self.assertFalse(arch.extract('foo.tar'))
call.assert_called_once_with(['tar', 'xf', 'foo.tar'])
call.reset_mock()
arch = file_archive.TarGzipArchive()
arch.archiver = 'tar'
call.return_value = 0
self.assertTrue(arch.create('foo'))
call.assert_called_once_with(['tar', 'zcf', 'foo', '.'])
self.assertTrue(arch.create('foo.tgz'))
call.assert_called_once_with(['tar', 'zcf', 'foo.tgz', 'foo'])
call.reset_mock()
call.return_value = 1
self.assertFalse(arch.extract('foo'))
call.assert_called_once_with(['tar', 'xf', 'foo'])
self.assertFalse(arch.extract('foo.tgz'))
call.assert_called_once_with(['tar', 'xf', 'foo.tgz'])
call.reset_mock()
arch = file_archive.TarBzip2Archive()
arch.archiver = 'tar'
call.return_value = 0
self.assertTrue(arch.create('foo'))
call.assert_called_once_with(['tar', 'jcf', 'foo', '.'])
self.assertTrue(arch.create('foo.tar.bz2'))
call.assert_called_once_with(['tar', 'jcf', 'foo.tar.bz2', 'foo'])
call.reset_mock()
call.return_value = 1
self.assertFalse(arch.extract('foo'))
call.assert_called_once_with(['tar', 'xf', 'foo'])
self.assertFalse(arch.extract('foo.tar.bz2'))
call.assert_called_once_with(['tar', 'xf', 'foo.tar.bz2'])
call.reset_mock()
arch = file_archive.TarXzArchive()
arch.archiver = 'tar'
call.return_value = 0
self.assertTrue(arch.create('foo'))
call.assert_called_once_with(['tar', 'Jcf', 'foo', '.'])
self.assertTrue(arch.create('foo.tar.xz'))
call.assert_called_once_with(['tar', 'Jcf', 'foo.tar.xz', 'foo'])
call.reset_mock()
call.return_value = 1
self.assertFalse(arch.extract('foo'))
call.assert_called_once_with(['tar', 'xf', 'foo'])
self.assertFalse(arch.extract('foo.tar.xz'))
call.assert_called_once_with(['tar', 'xf', 'foo.tar.xz'])
with open('bar', 'w') as fobj:
fobj.write('\n')
call.reset_mock()
arch = file_archive.TarGzipArchive()
arch.archiver = 'tar'
call.return_value = 0
self.assertTrue(arch.create('foo.tgz'))
call.assert_called_once_with(['tar', 'zcf', 'foo.tgz', 'bar', 'foo'])
@mock.patch('fs_uae_wrapper.path.which')
@mock.patch('subprocess.call')