diff options
author | Guido Günther <agx@sigxcpu.org> | 2019-10-26 20:16:37 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2019-10-27 11:35:45 +0100 |
commit | 49115ded58d8058a513b2d383691a7c81e053e8b (patch) | |
tree | 34bee842ac719d2decf0c302a7376a7deaa77911 /gbp | |
parent | 273e7bfb25326af58c29eef29d25b3e026c77e3e (diff) |
import_orig: Symlink signature as well if needed
Diffstat (limited to 'gbp')
-rw-r--r-- | gbp/scripts/import_orig.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index 2ebd279e..6c40ea0f 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -42,6 +42,22 @@ from gbp.scripts.common.hook import Hook from gbp.deb.rollbackgit import RollbackDebianGitRepository +def maybe_link(orig, link): + """ + Create a symlink named link pointing to orig if + that is not the case already. + """ + if is_link_target(orig, link): + return False + + 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(orig), link) + return True + + def prepare_pristine_tar(archive, pkg, version): """ Prepare the upstream source for pristine tar import. @@ -49,7 +65,7 @@ def prepare_pristine_tar(archive, pkg, version): This checks if the upstream source is actually a tarball and creates a symlink from I{archive} to I{<pkg>_<version>.orig.tar.<ext>} so pristine-tar will - see the correct basename. + see the correct basename. Same goes for an optional signature. @param archive: the upstream source's name @type archive: C{str} @@ -61,25 +77,21 @@ def prepare_pristine_tar(archive, pkg, version): """ linked = False if os.path.isdir(archive): - return None, None + return None, False ext = os.path.splitext(archive)[1] if ext in ['.tgz', '.tbz2', '.tlz', '.txz']: ext = ".%s" % ext[2:] link = "../%s_%s.orig.tar%s" % (pkg, version, ext) - 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 + linked = maybe_link(archive, link) + archive_sig = '{}.asc'.format(archive) + if os.path.exists(archive_sig): + maybe_link(archive_sig, '{}.asc'.format(link)) except OSError as err: - raise GbpError("Cannot symlink '%s' to '%s': %s" % (archive, link, err[1])) + raise GbpError("Cannot symlink '%s' to '%s': %s" % (archive, link, err)) return (link, linked) else: return (archive, linked) |