ソースを参照

allow downgrades using -e, clean up update decision code a bit

Michael van Elst 23 年 前
コミット
1fde3dff9a
3 ファイル変更48 行追加16 行削除
  1. 40 14
      openpkg-tool/openpkg-build.pl
  2. 2 2
      openpkg-tool/openpkg-tool.spec
  3. 6 0
      openpkg-tool/openpkg.pod

+ 40 - 14
openpkg-tool/openpkg-build.pl

@@ -33,8 +33,8 @@ use vars qw/
     $opt_R $opt_r $opt_f $opt_u $opt_U $opt_a $opt_A
     $opt_z $opt_Z $opt_P $opt_N $opt_E $opt_i $opt_D
     $opt_p $opt_q $opt_s $opt_S $opt_X $opt_M $opt_L
-    $opt_W $opt_K/;
-my $getopts = 'R:r:f:uUaAzZP:N:E:iD:p:qsSXMLWK';
+    $opt_W $opt_K $opt_e/;
+my $getopts = 'R:r:f:uUaAzZP:N:E:iD:p:qsSXMLWKe';
 getopts($getopts);
 
 ##########################################################################
@@ -112,7 +112,7 @@ if (open(FH, "< $ENV{'HOME'}/.openpkg/build")) {
     close(FH);
 }
 
-die "openpkg:build:USAGE: $0 [-R rpm] [-r repository] [-f index.rdf] [-uUzZiqsSXMLWK] [-P priv-cmd] [-N non-priv-cmd] [-p platform] [-Dwith ...] [-Ename ...] ( [-aA] | patternlist )\n"
+die "openpkg:build:USAGE: $0 [-R rpm] [-r repository] [-f index.rdf] [-uUzZiqsSXMLWKe] [-P priv-cmd] [-N non-priv-cmd] [-p platform] [-Dwith ...] [-Ename ...] ( [-aA] | patternlist )\n"
     unless $#ARGV >= 0 || ($#ARGV == -1 && ($opt_a || $opt_A));
 
 ##########################################################################
@@ -1248,16 +1248,41 @@ sub unique_map {
 }
 
 #
-# test wether target could be upgraded
+# determine wether target should be rebuild
 #
-sub target_newer ($$) {
-    my($target, $map) = @_;
+sub target_better ($$$) {
+    my($env, $target, $map) = @_;
     my($vs) = vs($target);
     my($vmap) = $map->{$target->{name}};
 
-    return 1 unless $vmap;
+    #
+    # rebuild if target isn't installed
+    #
+    return 'new' unless $vmap;
+
+    #
+    # always update GOALs
+    #
+    if ($target->{GOAL} && !grep { vcmp($vs, $_) <= 0; } keys %$vmap) {
+        return 'goal';
+    }
+    #
+    # if -e then
+    # always update if installed version is different from repository
+    #
+    if ($env->{exact} && !grep { vcmp($vs, $_) == 0; } keys %$vmap) {
+        return 'exact';
+    }
+    #
+    # if -U then
+    # always update if installed version is older than repository
+    #
+    if ($env->{upgrade} && !grep { vcmp($vs, $_) <= 0; } keys %$vmap) {
+        return 'upgrade';
+    }
 
-    return !grep { vcmp($vs, $_) <= 0; } keys %$vmap;
+    # keep installed target
+    return;
 }
 
 #
@@ -1366,8 +1391,7 @@ sub dep2target ($$) {
 
     $t = chose_source($env, $name, undef, $r, get_versions($r, $cond));
     if ($t) {
-        if (!$tdef ||
-            ($env->{upgrade} && target_newer($t, $env->{installed}))) {
+        if (!$tdef || target_better($env, $t, $env->{installed})) {
             return ($t, 0);
         }
     }
@@ -1385,7 +1409,7 @@ sub dep2target ($$) {
 sub make_dep ($$$$$$$) {
     my($who,$target,$depth,$env,$list,$blist,$clist) = @_;
     my($d,$k,%d,%k,$t,$old);
-    my(@deps,$conflict);
+    my(@deps,$conflict,$why);
 
     if (target_exists($target, $env->{built})) {
         print "# $target->{name} is already in list\n";
@@ -1421,9 +1445,9 @@ sub make_dep ($$$$$$$) {
         } elsif ($env->{zero}) {
             target_setstatus($target,'ZERO',1);
             print "# rebuilding $target->{name} (zero)\n";
-        } elsif (target_newer($target, $env->{installed})) {
-            target_setstatus($target,'UPGRADE',3);
-            print "# rebuilding $target->{name} (upgrade)\n";
+        } elsif ($why = target_better($env, $target, $env->{installed})) {
+            target_setstatus($target,'UPDATE',3);
+            print "# rebuilding $target->{name} ($why)\n";
         } elsif (!target_suitable($t, $env->{with})) {
             target_setstatus($target,'MISMATCH',2);
             print "# rebuilding $target->{name} (parameter mismatch)\n";
@@ -1623,6 +1647,7 @@ sub build_list ($$) {
 
         if ($t) {
             warn_about_options($t, $env->{with}, $env->{config});
+            $t->{GOAL} = 1;
             push(@goals, $t);
         } else {
             if ($env->{status}) {
@@ -2044,6 +2069,7 @@ $env = {
     exclude    => \%exclude,
     upgrade    => ($opt_a || $opt_U),
     zero       => ($opt_z || $opt_Z),
+    exact      => $opt_e,
     quick      => $opt_q,
     status     => ($opt_s || $opt_S),
     fatal      => [],

+ 2 - 2
openpkg-tool/openpkg-tool.spec

@@ -32,8 +32,8 @@ Packager:     The OpenPKG Project
 Distribution: OpenPKG [PLUS]
 Group:        Bootstrapping
 License:      GPL
-Version:      20030215
-Release:      20030215
+Version:      20030218
+Release:      20030218
 
 #   list of sources
 Source0:      openpkg.sh

+ 6 - 0
openpkg-tool/openpkg.pod

@@ -64,6 +64,7 @@ B<build>
 [B<-W>]
 [B<-X>]
 [B<-K>]
+[B<-e>]
 [B<-P> I<priv-cmd>]
 [B<-N> I<non-priv-cmd>]
 [B<-p> I<platform>]
@@ -283,6 +284,11 @@ simple text parser instead.
 
 Keep packages that were installed temporarily during the build process.
 
+=item B<-e>
+
+Rebuild exact version from repository even when you have installed
+a newer version from another repository.
+
 =item B<-P> I<priv-cmd>
 
 Command prefix to use for install commands that require elevated