]> err.no Git - dpkg/commitdiff
update-alternatives: Properly handle alternatives with inexistent slave links
authorGuillem Jover <guillem@debian.org>
Thu, 27 Dec 2007 05:43:18 +0000 (07:43 +0200)
committerGuillem Jover <guillem@debian.org>
Thu, 27 Dec 2007 06:49:10 +0000 (08:49 +0200)
Based on a patch by Daniel Leidert <daniel.leidert@wgdd.de>.
Closes: #76295, #246906, #433567, #451872, #220044, #392440, #441021
Closes: #443241
ChangeLog
debian/changelog
scripts/update-alternatives.pl

index 8158fc5bb1d0187126842d02873b3b0370c53ee2..0bc9e5172500a82f90f84594210e90590251732c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-12-27  Daniel Leidert  <daniel.leidert@wgdd.de>
+            Guillem Jover  <guillem@debian.org>
+
+       * scripts/update-alternatives.pl: Refactor duplicate code into ...
+       (checked_alternative): ... here. New function.
+       (set_links): Call it.
+
 2007-12-27  Guillem Jover  <guillem@debian.org>
 
        * scripts/update-alternatives.pl (gl): Use defined instead of length.
index b2d81868be249b8fac1bc0f4d85a6c0aca556017..f84c8ca9e404c10120fcedbc53b098e3f9f0632a 100644 (file)
@@ -41,6 +41,10 @@ dpkg (1.14.13) UNRELEASED; urgency=low
   * Ignore the man pages when building without NLS support. Closes: #457673
   * Fix perl warnings:
     - Check for undefined values when reading from the alternative db.
+  * Properly handle symlinks for alternatives with inexistent slave links.
+    Closes: #76295, #246906, #433567, #451872, #220044, #392440, #441021
+    Closes: #443241
+    Based on a patch by Daniel Leidert <daniel.leidert@wgdd.de>.
 
   [ Updated dpkg translations ]
   * Swedish (Peter Karlsson)
index 9c1089d63fc8176aee0bd04b0d22ca630110e93b..a7c85b4408d39e376a736aa600a044e71b8c1798 100755 (executable)
@@ -223,6 +223,32 @@ sub list_link_group
     }
 }
 
+sub checked_alternative($$$)
+{
+    my ($name, $link, $path) = @_;
+
+    $linkname = readlink($link);
+    if (!defined($linkname) && $! != ENOENT) {
+       pr(sprintf(_g("warning: %s is supposed to be a symlink to %s, \n".
+                     "or nonexistent; however, readlink failed: %s"),
+                  $link, "$altdir/$name", $!))
+           if $verbosemode > 0;
+    } elsif (!defined($linkname) ||
+            (defined($linkname) && $linkname ne "$altdir/$name")) {
+       checked_rm("$link.dpkg-tmp");
+       checked_symlink("$altdir/$name", "$link.dpkg-tmp");
+       checked_mv("$link.dpkg-tmp", $link);
+    }
+    $linkname = readlink("$altdir/$name");
+    if (defined($linkname) && $linkname eq $path) {
+       pr(sprintf(_g("Leaving %s (%s) pointing to %s."), $name, $link, $path))
+           if $verbosemode > 0;
+    } else {
+       pr(sprintf(_g("Updating %s (%s) to point to %s."), $name, $link, $path))
+           if $verbosemode > 0;
+    }
+}
+
 sub set_links($$)
 {
     my ($spath, $preferred) = (@_);
@@ -235,6 +261,8 @@ sub set_links($$)
     for (my $slnum = 0; $slnum < @slavenames; $slnum++) {
        my $slave = $slavenames[$slnum];
        if ($slavepath{$preferred, $slnum} ne '') {
+           checked_alternative($slave, $slavelinks[$slnum],
+                         $slavepath{$preferred, $slnum});
            checked_symlink($slavepath{$preferred, $slnum},
                            "$altdir/$slave.dpkg-tmp");
            checked_mv("$altdir/$slave.dpkg-tmp", "$altdir/$slave");
@@ -569,24 +597,7 @@ if ($mode eq 'auto') {
         checked_rm("$admindir/$name");
         exit(0);
     } else {
-       $linkname = readlink($link);
-       if (!defined($linkname) && $! != ENOENT) {
-            &pr(sprintf(_g("warning: %s is supposed to be a symlink to %s\n".
-                " (or nonexistent); however, readlink failed: %s"), $link, "$altdir/$name", $!))
-               if $verbosemode > 0;
-       } elsif (!defined($linkname) ||
-                (defined($linkname) && $linkname ne "$altdir/$name")) {
-            checked_rm("$link.dpkg-tmp");
-           checked_symlink("$altdir/$name", "$link.dpkg-tmp");
-           checked_mv("$link.dpkg-tmp", $link);
-        }
-        if (defined($linkname= readlink("$altdir/$name")) && $linkname eq $best) {
-            &pr(sprintf(_g("Leaving %s (%s) pointing to %s."), $name, $link, $best))
-              if $verbosemode > 0;
-        } else {
-            &pr(sprintf(_g("Updating %s (%s) to point to %s."), $name, $link, $best))
-              if $verbosemode > 0;
-        }
+       checked_alternative($name, $link, $best);
         checked_rm("$altdir/$name.dpkg-tmp");
         symlink($best,"$altdir/$name.dpkg-tmp");
     }
@@ -607,25 +618,7 @@ if ($mode eq 'auto') {
             checked_rm("$altdir/$sname");
             checked_rm("$slink");
         } else {
-           $linkname = readlink($slink);
-           if (!defined($linkname) && $! != ENOENT) {
-               pr(sprintf(_g("warning: %s is supposed to be a slave symlink to\n".
-                             " %s, or nonexistent; however, readlink failed: %s"),
-                          $slink, "$altdir/$sname", $!))
-                   if $verbosemode > 0;
-           } elsif (!defined($linkname) ||
-                   (defined($linkname) && $linkname ne "$altdir/$sname")) {
-               checked_rm("$slink.dpkg-tmp");
-               checked_symlink("$altdir/$sname", "$slink.dpkg-tmp");
-               checked_mv("$slink.dpkg-tmp", $slink);
-           }
-            if (defined($linkname= readlink("$altdir/$sname")) && $linkname eq $spath) {
-                &pr(sprintf(_g("Leaving %s (%s) pointing to %s."), $sname, $slink, $spath))
-                  if $verbosemode > 0;
-            } else {
-                &pr(sprintf(_g("Updating %s (%s) to point to %s."), $sname, $slink, $spath))
-                  if $verbosemode > 0;
-            }
+           checked_alternative($sname, $slink, $spath);
            checked_symlink("$spath", "$altdir/$sname.dpkg-tmp");
            checked_mv("$altdir/$sname.dpkg-tmp", "$altdir/$sname");
         }