From: Guillem Jover Date: Thu, 27 Dec 2007 03:54:09 +0000 (+0200) Subject: update-alternatives: Refactor duplicate code into new set_links function X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=294f86c859f6bce82b66861a9dc19c31483df6c0;p=dpkg update-alternatives: Refactor duplicate code into new set_links function --- diff --git a/ChangeLog b/ChangeLog index 559bd53c..a40ccb24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-12-27 Guillem Jover + + * scripts/update-alternatives.pl (set_links): New function. + (config_alternatives): Use set_links instead of duped code. + (set_alternatives): Likewise. + 2007-12-27 Guillem Jover * scripts/update-alternatives.pl: Refactor all code to use diff --git a/scripts/update-alternatives.pl b/scripts/update-alternatives.pl index b00c4795..463b61d2 100755 --- a/scripts/update-alternatives.pl +++ b/scripts/update-alternatives.pl @@ -223,6 +223,30 @@ sub list_link_group } } +sub set_links($$) +{ + my ($spath, $preferred) = (@_); + + printf STDOUT _g("Using '%s' to provide '%s'.") . "\n", $spath, $name; + checked_symlink("$spath","$altdir/$name.dpkg-tmp"); + checked_mv("$altdir/$name.dpkg-tmp", "$altdir/$name"); + + # Link slaves... + for (my $slnum = 0; $slnum < @slavenames; $slnum++) { + my $slave = $slavenames[$slnum]; + if ($slavepath{$preferred, $slnum} ne '') { + checked_symlink($slavepath{$preferred, $slnum}, + "$altdir/$slave.dpkg-tmp"); + checked_mv("$altdir/$slave.dpkg-tmp", "$altdir/$slave"); + } else { + pr(sprintf(_g("Removing %s (%s), not appropriate with %s."), $slave, + $slavelinks[$slnum], $versions[$preferred])) + if $verbosemode > 0; + checked_rm("$altdir/$slave"); + } + } +} + sub check_many_actions() { return unless $action; @@ -647,24 +671,9 @@ sub config_alternatives { if ($preferred ne '') { $mode = "manual"; $preferred--; - printf STDOUT _g("Using \`%s' to provide \`%s'.")."\n", $versions[$preferred], $name; my $spath = $versions[$preferred]; - checked_symlink("$spath", "$altdir/$name.dpkg-tmp"); - checked_mv("$altdir/$name.dpkg-tmp", "$altdir/$name"); - # Link slaves... - for( my $slnum = 0; $slnum < @slavenames; $slnum++ ) { - my $slave = $slavenames[$slnum]; - if ($slavepath{$preferred,$slnum} ne '') { - checked_symlink($slavepath{$preferred,$slnum}, - "$altdir/$slave.dpkg-tmp"); - checked_mv("$altdir/$slave.dpkg-tmp", "$altdir/$slave"); - } else { - &pr(sprintf(_g("Removing %s (%s), not appropriate with %s."), $slave, $slavelinks[$slnum], $versions[$preferred])) - if $verbosemode > 0; - checked_rm("$altdir/$slave"); - } - } + set_links($spath, $preferred); } } @@ -681,22 +690,7 @@ sub set_alternatives { if($preferred == -1){ &quit(sprintf(_g("Cannot find alternative `%s'."), $apath)."\n") } - printf STDOUT _g("Using \`%s' to provide \`%s'.")."\n", $apath, $name; - checked_symlink("$apath", "$altdir/$name.dpkg-tmp"); - checked_mv("$altdir/$name.dpkg-tmp", "$altdir/$name"); - # Link slaves... - for (my $slnum = 0; $slnum < @slavenames; $slnum++ ) { - my $slave = $slavenames[$slnum]; - if ($slavepath{$preferred,$slnum} ne '') { - checked_symlink($slavepath{$preferred,$slnum}, - "$altdir/$slave.dpkg-tmp"); - checked_mv("$altdir/$slave.dpkg-tmp", "$altdir/$slave"); - } else { - &pr(sprintf(_g("Removing %s (%s), not appropriate with %s."), $slave, $slavelinks[$slnum], $versions[$preferred])) - if $verbosemode > 0; - checked_rm("$altdir/$slave"); - } - } + set_links($apath, $preferred); } sub pr { print(STDOUT "@_\n") || &quit(sprintf(_g("error writing stdout: %s"), $!)); }