aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-01-10 19:24:58 +0100
committerGuido Günther <agx@sigxcpu.org>2017-01-11 10:53:43 +0100
commit5fb074984bad0500245bd491e0a1eea9c69b0f8f (patch)
tree5c41b2698ba2882aba7155359349ca44477d2d38
parent629e79eb3800da1f9301e5d11a378e6ae7abcffa (diff)
import_orig: Delay unpack of component tarballs
Instead of unpacking them right away first repack the filtered tarball so the component tarballs don't end up in the main tarball when using filters. Closes: #840602
-rw-r--r--gbp/scripts/import_orig.py8
-rw-r--r--tests/component/deb/test_import_orig.py46
2 files changed, 50 insertions, 4 deletions
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index 2e139ab..5c94827 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -537,17 +537,19 @@ def main(argv):
if repo.bare:
set_bare_repo_options(options)
- if not source.is_dir():
+ if not source.is_dir(): # Unpack main tarball
tmpdir = tempfile.mkdtemp(dir='../')
source.unpack(tmpdir, options.filters)
gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked))
- for (component, tarball) in component_tarballs:
- unpack_component_tarball(source.unpacked, component, tarball, options.filters)
if orig_needs_repack(source, options):
gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked))
(source, tmpdir) = repack_source(source, sourcepackage, version, tmpdir, options.filters)
+ if not source.is_dir(): # Unpack component tarballs
+ for (component, tarball) in component_tarballs:
+ unpack_component_tarball(source.unpacked, component, tarball, options.filters)
+
(pristine_orig, linked) = prepare_pristine_tar(source.path,
sourcepackage,
version)
diff --git a/tests/component/deb/test_import_orig.py b/tests/component/deb/test_import_orig.py
index 26a14d5..a9b7645 100644
--- a/tests/component/deb/test_import_orig.py
+++ b/tests/component/deb/test_import_orig.py
@@ -17,6 +17,8 @@
# <http://www.gnu.org/licenses/>
import os
+import shutil
+import tarfile
from mock import patch, DEFAULT
@@ -31,7 +33,7 @@ from gbp.deb.pristinetar import DebianPristineTar
from gbp.deb.dscfile import DscFile
from gbp.git.repository import GitRepository, GitRepositoryError
-from nose.tools import ok_, eq_
+from nose.tools import ok_, eq_, assert_raises
def raise_if_tag_match(match):
@@ -251,3 +253,45 @@ class TestImportOrig(ComponentTestBase):
ok_(import_orig(['arg0', '--no-interactive', '--pristine-tar', orig]) == 1)
self._check_repo_state(repo, None, [], tags=[])
+
+ def test_filter_with_component_tarballs(self):
+ """
+ Test that using a filter works even with component tarballs (#840602)
+ """
+ dsc = self._dsc('2.6-2')
+ ok_(import_dsc(['arg0', '--pristine-tar', dsc]) == 0)
+ repo = ComponentTestGitRepository(self.pkg)
+ os.chdir(self.pkg)
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'])
+
+ # copy data since we don't want the repacked tarball to end up in DEB_TEST_DATA_DIR
+ os.mkdir('../tarballs')
+ for f in ['hello-debhelper_2.8.orig-foo.tar.gz', 'hello-debhelper_2.8.orig.tar.gz']:
+ src = os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0-additional-tarballs', f)
+ shutil.copy(src, '../tarballs')
+
+ ok_(import_orig(['arg0',
+ '--component=foo',
+ '--no-interactive',
+ '--pristine-tar',
+ '--filter-pristine-tar',
+ '--filter=README*',
+ '../tarballs/hello-debhelper_2.8.orig.tar.gz']) == 0)
+ self._check_repo_state(repo, 'master', ['master', 'upstream', 'pristine-tar'],
+ tags=['debian/2.6-2', 'upstream/2.6', 'upstream/2.8'])
+ self._check_component_tarballs(repo, ['foo/test1', 'foo/test2'])
+
+ ok_('README' not in repo.ls_tree('HEAD'),
+ "README not filtered out of %s" % repo.ls_tree('HEAD'))
+ tar = '../hello-debhelper_2.8.orig.tar.gz'
+
+ # Check if tar got filtered properly
+ ok_(os.path.exists(tar))
+ t = tarfile.open(name=tar, mode="r:gz")
+ for f in ['hello-2.8/configure']:
+ i = t.getmember(f)
+ eq_(type(i), tarfile.TarInfo)
+ for f in ['hello-2.8/README']:
+ with assert_raises(KeyError):
+ t.getmember(f)
+ t.close()