]> err.no Git - dpkg/commitdiff
update-alternatives: Refactor duplicate code into new set_links function
authorGuillem Jover <guillem@debian.org>
Thu, 27 Dec 2007 03:54:09 +0000 (05:54 +0200)
committerGuillem Jover <guillem@debian.org>
Thu, 27 Dec 2007 04:27:27 +0000 (06:27 +0200)
ChangeLog
scripts/update-alternatives.pl

index 559bd53c50e5e33d616e8922d896348d1104cc31..a40ccb2449ec5b37d7a5f5048347d1483bcbc28f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-12-27  Guillem Jover  <guillem@debian.org>
+
+       * 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  <guillem@debian.org>
 
        * scripts/update-alternatives.pl: Refactor all code to use
index b00c479588e44475d8f4b0f1b5de242c82088f6e..463b61d27587a3f52c24b8c294bc6cd751370424 100755 (executable)
@@ -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"), $!)); }