From bb457825c68c9b279f2e57fd5d771147a38fe4ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20O=C5=BCarowski?= <piotr@debian.org>
Date: Sun, 10 Jun 2012 14:06:26 +0200
Subject: [PATCH] dh_python2: remove even more \.so.* dangling symlinks, thanks
 to Stefano Rivera for providing a test case

---
 debian/changelog      | 7 +++++++
 dh_python2            | 5 +++++
 tests/t3/Makefile     | 4 ++++
 tests/t3/debian/rules | 8 ++++++++
 4 files changed, 24 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index e0c9f19..17f10e6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+python-defaults (2.7.3~rc2-2) unstable; urgency=low
+
+  * dh_python2: remove even more \.so.* dangling symlinks, thanks to Stefano
+    Rivera for providing a test case
+
+ -- Piotr Ożarowski <piotr@debian.org>  Sun, 10 Jun 2012 13:52:38 +0200
+
 python-defaults (2.7.3~rc2-1) unstable; urgency=low
 
   [ Scott Kitterman ]
diff --git a/dh_python2 b/dh_python2
index fb080c2..95e3467 100755
--- a/dh_python2
+++ b/dh_python2
@@ -380,6 +380,11 @@ def scan(package, dname=None, clean_dbg_pkg=True):
             fpath = join(root, fn)
             if not exists(fpath):
                 # could be removed while handling .so symlinks
+                if islink(fpath) and '.so.' in split(fpath)[-1]:
+                    # dangling symlink to (now removed/renamed) .so file
+                    # which wasn't removed yet (see test3's quux.so.0)
+                    log.info('removing symlink: %s', fpath)
+                    os.remove(fpath)
                 continue
             fext = fn.rsplit('.', 1)[-1]
             if fext in ('pyc', 'pyo'):
diff --git a/tests/t3/Makefile b/tests/t3/Makefile
index 96032f8..2a17279 100644
--- a/tests/t3/Makefile
+++ b/tests/t3/Makefile
@@ -17,6 +17,10 @@ check:
 	test -f debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/baz.so
 	test ! -f debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/baz.so.0.1
 	test ! -f debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/baz.so.0.1.2
+	test -f debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/quux.so
+	test ! -f debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/quux.so.0
+	test ! -L debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/quux.so.0
+	test ! -f debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/quux.so.0.0.0
 
 clean:
 	./debian/rules clean
diff --git a/tests/t3/debian/rules b/tests/t3/debian/rules
index 0915111..7ce8185 100755
--- a/tests/t3/debian/rules
+++ b/tests/t3/debian/rules
@@ -19,4 +19,12 @@ override_dh_pysupport:
 		/usr/lib/python${DPY}/dist-packages/foo/baz.so.0.1
 	dh_link /usr/lib/python${DPY}/dist-packages/foo/baz.so.0.1 \
 		/usr/lib/python${DPY}/dist-packages/foo/baz.so
+	# ... second style of multiple symlinks
+	cp debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/bar.so \
+	   debian/python-foo/usr/lib/python${DPY}/dist-packages/foo/quux.so.0.0.0
+	dh_link /usr/lib/python${DPY}/dist-packages/foo/quux.so.0.0.0 \
+		/usr/lib/python${DPY}/dist-packages/foo/quux.so.0
+	dh_link /usr/lib/python${DPY}/dist-packages/foo/quux.so.0.0.0 \
+		/usr/lib/python${DPY}/dist-packages/foo/quux.so
+	# ... and complex multiple symlinks
 	DH_VERBOSE=1 ../../dh_python2
-- 
GitLab