summaryrefslogtreecommitdiff
path: root/gbp/scripts
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-08-27 19:22:44 +0300
committerGuido Günther <agx@sigxcpu.org>2013-09-10 09:15:43 +0200
commite54289ef2a5f72456834de3a21c2e6c3f2ebdb6b (patch)
tree14da3a0a0c8dba35ffab3a4319b9be3ba0676ba8 /gbp/scripts
parentf738be32630724eb5f8c53035b1571e45cd547f4 (diff)
common/buildpackage: fix handling of empty tarball prefix
Previously empty prefix in tarball generation introduced a leading slash in all filenames in the archive. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/scripts')
-rw-r--r--gbp/scripts/common/buildpackage.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py
index c80a24f..0522cd6 100644
--- a/gbp/scripts/common/buildpackage.py
+++ b/gbp/scripts/common/buildpackage.py
@@ -34,6 +34,22 @@ wc_name = "WC"
wc_index = ".git/gbp_index"
+def sanitize_prefix(prefix):
+ """
+ Sanitize the prefix used for generating source archives
+
+ >>> sanitize_prefix('')
+ '/'
+ >>> sanitize_prefix('foo/')
+ 'foo/'
+ >>> sanitize_prefix('/foo/bar')
+ 'foo/bar/'
+ """
+ if prefix:
+ return prefix.strip('/') + '/'
+ return '/'
+
+
def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, comp_opts):
"""
Create tar.gz of an archive with submodules
@@ -43,13 +59,13 @@ def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level,
Exception handling is left to the caller.
"""
-
+ prefix = sanitize_prefix(prefix)
tarfile = output.rsplit('.', 1)[0]
tempdir = tempfile.mkdtemp()
submodule_tarfile = os.path.join(tempdir, "submodule.tar")
try:
# generate main tarfile
- repo.archive(format='tar', prefix='%s/' % (prefix),
+ repo.archive(format='tar', prefix=prefix,
output=tarfile, treeish=treeish)
# generate each submodule's tarfile and append it to the main archive
@@ -57,7 +73,7 @@ def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level,
tarpath = [subdir, subdir[2:]][subdir.startswith("./")]
gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8]))
- repo.archive(format='tar', prefix='%s/%s/' % (prefix, tarpath),
+ repo.archive(format='tar', prefix='%s%s/' % (prefix, tarpath),
output=submodule_tarfile, treeish=commit, cwd=subdir)
CatenateTarArchive(tarfile)(submodule_tarfile)
@@ -75,8 +91,9 @@ def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts
Exception handling is left to the caller.
"""
+ prefix = sanitize_prefix(prefix)
pipe = pipes.Template()
- pipe.prepend("git archive --format=tar --prefix=%s/ %s" % (prefix, treeish), '.-')
+ pipe.prepend("git archive --format=tar --prefix=%s %s" % (prefix, treeish), '.-')
pipe.append('%s -c -%s %s' % (comp_type, comp_level, comp_opts), '--')
ret = pipe.copy('', output)
if ret:
@@ -87,10 +104,10 @@ def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts
def dump_tree(repo, export_dir, treeish, with_submodules):
"dump a tree to output_dir"
output_dir = os.path.dirname(export_dir)
- prefix = os.path.basename(export_dir)
+ prefix = sanitize_prefix(os.path.basename(export_dir))
pipe = pipes.Template()
- pipe.prepend('git archive --format=tar --prefix=%s/ %s' % (prefix, treeish), '.-')
+ pipe.prepend('git archive --format=tar --prefix=%s %s' % (prefix, treeish), '.-')
pipe.append('tar -C %s -xf -' % output_dir, '-.')
top = os.path.abspath(os.path.curdir)
try:
@@ -106,7 +123,7 @@ def dump_tree(repo, export_dir, treeish, with_submodules):
tarpath = [subdir, subdir[2:]][subdir.startswith("./")]
os.chdir(subdir)
pipe = pipes.Template()
- pipe.prepend('git archive --format=tar --prefix=%s/%s/ %s' %
+ pipe.prepend('git archive --format=tar --prefix=%s%s/ %s' %
(prefix, tarpath, commit), '.-')
pipe.append('tar -C %s -xf -' % output_dir, '-.')
ret = pipe.copy('', '')