From ec613d37849f1d35bc2f076ca54805d92039ab78 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 27 Dec 2007 07:43:18 +0200 Subject: [PATCH] update-alternatives: Properly handle alternatives with inexistent slave links Based on a patch by Daniel Leidert . Closes: #76295, #246906, #433567, #451872, #220044, #392440, #441021 Closes: #443241 --- ChangeLog | 7 ++++ debian/changelog | 4 ++ scripts/update-alternatives.pl | 67 +++++++++++++++------------------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8158fc5b..0bc9e517 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-12-27 Daniel Leidert + Guillem Jover + + * scripts/update-alternatives.pl: Refactor duplicate code into ... + (checked_alternative): ... here. New function. + (set_links): Call it. + 2007-12-27 Guillem Jover * scripts/update-alternatives.pl (gl): Use defined instead of length. diff --git a/debian/changelog b/debian/changelog index b2d81868..f84c8ca9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 . [ Updated dpkg translations ] * Swedish (Peter Karlsson) diff --git a/scripts/update-alternatives.pl b/scripts/update-alternatives.pl index 9c1089d6..a7c85b44 100755 --- a/scripts/update-alternatives.pl +++ b/scripts/update-alternatives.pl @@ -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"); } -- 2.39.5