From f28420ecaa0797d2e36b135f70a1a54a9b4173cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20O=C5=BCarowski?= <piotr@debian.org>
Date: Sat, 15 Jan 2011 21:33:45 +0100
Subject: [PATCH] dh_python2: replace a file with a symlink also if there's a
 matching one in pyshared directory already

---
 debian/changelog |  7 +++++--
 dh_python2       | 10 +++++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index ac15879..b55eafa 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,7 +1,10 @@
 python-defaults (2.6.6-11) UNRELEASED; urgency=low
 
-  * dh_python2: fix parsing .pyinstall files (a space between file name and
-    module name is now required)
+  * dh_python2:
+    - fix parsing .pyinstall files (a space between file name and
+      module name is now required)
+    - replace a file with a symlink also if there's a matching one in
+      pyshared directory already
 
  -- Piotr Ożarowski <piotr@debian.org>  Sat, 15 Jan 2011 21:14:38 +0100
 
diff --git a/dh_python2 b/dh_python2
index bc10c7a..776bf48 100755
--- a/dh_python2
+++ b/dh_python2
@@ -26,7 +26,7 @@ import logging
 import os
 import re
 import sys
-from filecmp import dircmp, cmpfiles
+from filecmp import dircmp, cmpfiles, cmp as fcmp
 from optparse import OptionParser, SUPPRESS_HELP
 from os.path import isdir, islink, exists, join, realpath
 from shutil import rmtree, copy as fcopy
@@ -261,8 +261,12 @@ def share_2x(dir1, dir2, dc=None):
         # do not touch symlinks created by previous loop or other tools
         if dc and not islink(fpath1):
             # replace with a link to pyshared
-            os.rename(fpath1, fpath3)
-            relative_symlink(fpath3, fpath1)
+            if not exists(fpath3):
+                os.rename(fpath1, fpath3)
+                relative_symlink(fpath3, fpath1)
+            elif fcmp(fpath3, fpath1, shallow=False):
+                os.remove(fpath1)
+                relative_symlink(fpath3, fpath1)
         if dc is None:  # guess/copy mode
             if islink(fpath1):
                 # ralative links will work as well, it's always the same level
-- 
GitLab