From a6f5472e6fc3318173f3fbf02b2520ef37c20b3d Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 13 Nov 2008 15:52:11 +0100 Subject: Don't fail on symlink creation iff the symlink already points to the correct target. This way it doesn't make a difference if one points git-import-orig to the file downloaded via uscan or to the symlink created by uscan. Closes: #502565 --- git-import-orig | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'git-import-orig') diff --git a/git-import-orig b/git-import-orig index 95ea1b5d..fac26b33 100755 --- a/git-import-orig +++ b/git-import-orig @@ -39,6 +39,14 @@ def cleanup_tmp_tree(tree): print >>sys.stderr, "Removal of tmptree %s failed." % tree +def is_link_target(target, link): + """does symlink link already point to target?""" + if os.path.exists(link): + if os.path.samefile(target, link): + return True + return False + + def symlink_orig(archive, pkg, version): """ create a symlink _.orig.tar.gz so pristine-tar will see the @@ -48,13 +56,14 @@ def symlink_orig(archive, pkg, version): if os.path.isdir(archive): return None ext = os.path.splitext(archive)[1] - dst = "../%s_%s.orig.tar%s" % (pkg, version, ext) - if os.path.basename(archive) != os.path.basename(dst): + link = "../%s_%s.orig.tar%s" % (pkg, version, ext) + if os.path.basename(archive) != os.path.basename(link): try: - os.symlink(os.path.abspath(archive), dst) + if not is_link_target(archive, link): + os.symlink(os.path.abspath(archive), link) except OSError, err: - raise GbpError, "Cannot symlink '%s' to '%s': %s" % (archive, dst, err[1]) - return dst + raise GbpError, "Cannot symlink '%s' to '%s': %s" % (archive, link, err[1]) + return link else: return archive -- cgit v1.2.3