Browse Source

Remove all invalid master alternatives found

Initially I wanted to cleanup only problematic cases thinking that there
would be few. But apparently there must be an old version of
update-alternatives that created improper entries for slave alternatives
in /var/lib/dpkg/alternatives so I do a full scan once when we upgrade
from a version older than 1.15.3 and hope that we can forget about those
upgrade issues after that.
Raphael Hertzog 17 years ago
parent
commit
2cf5b0f90d
3 changed files with 33 additions and 14 deletions
  1. 2 2
      debian/changelog
  2. 5 0
      debian/dpkg.lintian-overrides
  3. 26 12
      debian/dpkg.preinst

+ 2 - 2
debian/changelog

@@ -9,8 +9,8 @@ dpkg (1.15.3) UNRELEASED; urgency=low
   [ Raphael Hertzog ]
   * Unset TAR_OPTIONS when creating/extracting tar archives for source
     packages. Closes: #530860
-  * Add cleanup of known invalid (master) alternatives in preinst script.
-    Closes: #530633, #531611, #532739
+  * Add cleanup of all invalid (master) alternatives in preinst script.
+    Closes: #530633, #531611, #532739, #521760
   * Let update-alternatives fix a manual alternative with a dangling symlink
     by switching it to automatic mode. Closes: #529999
   * Add missing paragraph separator in dpkg-buildpackage(1). Thanks to Per

+ 5 - 0
debian/dpkg.lintian-overrides

@@ -3,3 +3,8 @@ dpkg: redundant-bugs-field
 dpkg: arch-dep-package-has-big-usr-share
 # By design, to be able to recover from broken/missing zlib
 dpkg: embedded-zlib ./usr/bin/dpkg-deb
+# False positives, we read from a file not from a tty
+dpkg: read-in-maintainer-script preinst:38
+dpkg: read-in-maintainer-script preinst:39
+dpkg: read-in-maintainer-script preinst:41
+dpkg: read-in-maintainer-script preinst:49

+ 26 - 12
debian/dpkg.preinst

@@ -26,15 +26,30 @@ upgrade_dpkg_non_conffile()
     fi
 }
 
-clean_alternative()
-{
+kill_bad_alternatives () {
+    local IFS=""
     ALTDIR="/var/lib/dpkg/alternatives"
-    if [ -e "$ALTDIR/$2" ]; then
-        if [ -e "$ALTDIR/$1" ] && grep -q "^$2$" "$ALTDIR/$1"; then
-            echo "Removing conflicting alternative $2 ..."
-            rm -f "$ALTDIR/$2"
+    for alt in $ALTDIR/*; do
+        if [ ! -e $alt ]; then
+            # In case it's been removed by the code below
+            continue
         fi
-    fi
+        {
+            read mode
+            read mainlink
+            while true; do
+                read slave
+                if [ "$slave" = "" ]; then
+                    break
+                fi
+                if [ -e "$ALTDIR/$slave" ]; then
+                    echo "Removing conflicting master alternative $slave (it is slave of $(basename $alt))..."
+                    rm -f "$ALTDIR/$slave"
+                fi
+                read slavelink
+            done
+        } <$alt
+    done
 }
 
 case "$1" in
@@ -43,11 +58,10 @@ case "$1" in
 
     upgrade)
         # Cleanup bad alternatives that would choke with new
-        # update-alternatives (see #530633, #531611, #532739)
-        clean_alternative x-terminal-emulator x-terminal-emulator.1.gz
-        clean_alternative x-session-manager x-session-manager.1.gz
-        clean_alternative x-window-manager x-window-manager.1.gz
-        clean_alternative awk nawk
+        # update-alternatives (see #530633, #531611, #532739, #521760)
+        if dpkg --compare-versions "$2" lt 1.15.3; then
+            kill_bad_alternatives
+        fi
 
 	case "$2" in
 	    # Upgrade from pre-conffile dpkg.cfg