aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-01-11 19:00:48 +0100
committerGuido Günther <agx@sigxcpu.org>2017-01-11 19:01:10 +0100
commit4a41d496a8006fdc05e4eb0faf762d6ad043a96e (patch)
treeda46f0f9038b537ac224fbb72aebaf8812b37049
parent734143b4e0a53a044a20a569ed41632cc90ff360 (diff)
import-orig: Move orig.tar.gz with filter-pristine-tar
If we filter a tarball and use filter-pristine-tar we want pristine-tar to see the correct file name. If a file already exists at that location move it. If we wouldn't move the existing tarball but rather e.g. create the symlink in a temp directory we risk gbp buildpackage picking up the unfiltered tarball later. Closes: #558777
-rw-r--r--gbp/scripts/import_orig.py6
-rw-r--r--tests/component/deb/test_import_orig.py38
2 files changed, 44 insertions, 0 deletions
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index 5c94827..df2b0cb 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -18,8 +18,10 @@
"""Import a new upstream version into a Git repository"""
import os
+import shutil
import sys
import tempfile
+import time
import gbp.command_wrappers as gbpc
from gbp.deb import (DebianPkgPolicy, parse_changelog_repo)
from gbp.deb.upstreamsource import DebianUpstreamSource, unpack_component_tarball
@@ -197,6 +199,10 @@ def prepare_pristine_tar(archive, pkg, version):
if os.path.basename(archive) != os.path.basename(link):
try:
if not is_link_target(archive, link):
+ if os.path.exists(link):
+ backup = "%s.%d" % (link, time.time())
+ gbp.log.info("%s already exists, moving to %s" % (link, backup))
+ shutil.move(link, backup)
os.symlink(os.path.abspath(archive), link)
linked = True
except OSError as err:
diff --git a/tests/component/deb/test_import_orig.py b/tests/component/deb/test_import_orig.py
index a9b7645..d9e171e 100644
--- a/tests/component/deb/test_import_orig.py
+++ b/tests/component/deb/test_import_orig.py
@@ -295,3 +295,41 @@ class TestImportOrig(ComponentTestBase):
with assert_raises(KeyError):
t.getmember(f)
t.close()
+
+ def test_filter_with_orig_tarball(self):
+ """
+ Test that using a filter works even with an upstream tarball
+ that has already the correct name (#558777)
+ """
+ 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'])
+
+ f = 'hello-debhelper_2.8.orig.tar.gz'
+ src = os.path.join(DEB_TEST_DATA_DIR, 'dsc-3.0', f)
+ shutil.copy(src, '..')
+
+ ok_(import_orig(['arg0',
+ '--no-interactive',
+ '--pristine-tar',
+ '--filter-pristine-tar',
+ '--filter=README*',
+ '../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'])
+
+ filtered = os.path.join('..', f)
+ ok_(os.path.exists(filtered))
+ eq_(os.readlink(filtered).split('/')[-1],
+ 'hello-debhelper_2.8.orig.gbp.tar.gz')
+ # Check if tar got filtered properly
+ t = tarfile.open(name=filtered, 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()