Don't fail on symlink creation
authorGuido Günther <agx@sigxcpu.org>
Thu, 13 Nov 2008 14:52:11 +0000 (15:52 +0100)
committerGuido Guenther <agx@sigxcpu.org>
Thu, 13 Nov 2008 14:52:11 +0000 (15:52 +0100)
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

index 95ea1b5d87c933f27ad162f47e098260f6b846d1..fac26b331fe2e198aad2005d79ae0b377254768c 100755 (executable)
@@ -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 <pkg>_<version>.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