diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-11-22 09:18:56 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-11-22 09:18:56 +0000 |
commit | ede454237040f8cb3bde0260178b9c77070cd3ec (patch) | |
tree | 3b5da845703c03333f948d6fb947b0ce9901d359 /usr.sbin | |
parent | 267d700eb917859ff12796ac5d25b0e6609b54f2 (diff) |
change the timing a bit: create a list of updateset first, and process
them later.
To do that, normal additions go through hint2, and the findtruelocation
code moves to Update.pm
This will allow for more systematic handling of all names (including solving
more stuff on the fly, instead of upfront).
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 115 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 14 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 79 |
3 files changed, 117 insertions, 91 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm index 52b12c78777..c294763bd0b 100644 --- a/usr.sbin/pkg_add/OpenBSD/Update.pm +++ b/usr.sbin/pkg_add/OpenBSD/Update.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Update.pm,v 1.99 2009/11/17 10:17:21 espie Exp $ +# $OpenBSD: Update.pm,v 1.100 2009/11/22 09:18:55 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -17,6 +17,30 @@ use strict; use warnings; +package OpenBSD::Handle; +sub update +{ + my ($self, $updater, $set, $state) = @_; + + return $updater->process_handle($set, $self, $state); +} + +package OpenBSD::hint; +sub update +{ + my ($self, $updater, $set, $state) = @_; + + return $updater->process_hint($set, $self, $state); +} + +package OpenBSD::hint2; +sub update +{ + my ($self, $updater, $set, $state) = @_; + + return $updater->process_hint2($set, $self, $state); +} + package OpenBSD::Update; use OpenBSD::PackageInfo; use OpenBSD::PackageLocator; @@ -30,23 +54,25 @@ sub new return bless {}, $class; } -sub add_updateset +sub add_handle +{ + my ($self, $set, $old, $n) = @_; + $old->{update} = $n; + $set->add_newer($n); +} + +sub add_location { my ($self, $set, $handle, $location) = @_; - my $n = OpenBSD::Handle->from_location($location); - $handle->{done} = $n; - $set->add_newer($n); + $self->add_handle($set, $handle, + OpenBSD::Handle->from_location($location)); } sub process_handle { my ($self, $set, $h, $state) = @_; my $pkgname = $h->pkgname; - if (defined $h->{update}) { - $state->say("Update to $pkgname already found"); - return 0; - } if ($pkgname =~ m/^(?:\.libs\d*|partial)\-/o) { $state->say("Not updating $pkgname, remember to clean it"); @@ -111,7 +137,7 @@ sub process_handle if (@$l == 1) { if ($state->{defines}->{pkgpath}) { $state->say("Directly updating $pkgname -> ", $l->[0]->name); - $self->add_updateset($set, $h, $l->[0]); + $self->add_location($set, $h, $l->[0]); return 1; } if (defined $found && $found eq $l->[0] && @@ -128,7 +154,7 @@ sub process_handle my $r = $state->choose_location($pkgname, $l); if (defined $r) { - $self->add_updateset($set, $h, $r); + $self->add_location($set, $h, $r); return 1; } else { $state->{issues} = 1; @@ -154,46 +180,73 @@ sub process_hint } my $r = $state->choose_location($hint_name, $l); if (defined $r) { - $self->add_updateset($set, $hint, $r); + $self->add_location($set, $hint, $r); return 1; } else { return 0; } } -sub process_set +my $cache = {}; + +sub process_hint2 { - my ($self, $set, $state) = @_; - my $problem; - my $need_update; - for my $h ($set->older) { - next if $h->{done}; - my $r = $self->process_handle($set, $h, $state); - if (!defined $r) { - $problem = 1; + my ($self, $set, $hint, $state) = @_; + my $pkgname = $hint->pkgname; + if (OpenBSD::PackageName::is_stem($pkgname)) { + my ($h, $path, $repo); + if ($pkgname =~ m/\//o) { + ($repo, $path, $pkgname) = OpenBSD::PackageLocator::path_parse($pkgname); + $h = $repo; + } else { + $h = 'OpenBSD::PackageLocator'; + $path = ""; + } + my $l = $state->updater->stem2location($h, $pkgname, $state); + if (defined $l) { + $self->add_ulocation($set, $hint, $l); + } else { + return undef; } - if ($r) { - $need_update = 1; + } else { + if (!defined $cache->{$pkgname}) { + $self->add_handle($set, $hint, OpenBSD::Handle->create_new($pkgname)); + $cache->{$pkgname} = 1; } } - for my $h ($set->hints) { - next if $h->{done}; - my $r = $self->process_hint($set, $h, $state); - if (!defined $r) { + OpenBSD::Add::tag_user_packages($set); + return 1; +} + +sub process_set +{ + my ($self, $set, $state) = @_; + my $problem; + for my $h ($set->older, $set->hints) { + next if $h->{update}; + if (!defined $h->update($self, $set, $state)) { $problem = 1; } - if ($r) { - $need_update = 1; - } } if ($problem) { $state->tracker->mark_cant_update($set); return 0; - } elsif (!$need_update) { + } elsif ($set->newer == 0) { $state->tracker->mark_uptodate($set); return 0; } + $state->tracker->add_set($set); return 1; } +sub stem2location +{ + my ($self, $repo, $name, $state) = @_; + my $l = $repo->match_locations(OpenBSD::Search::Stem->new($name)); + if (@$l > 1 && !$state->{defines}->{allversions}) { + $l = OpenBSD::Search::FilterLocation->keep_most_recent->filter_locations($l); + } + return $state->choose_location($name, $l); +} + 1; diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index d78ce1e3ca2..7421273a58f 100644 --- a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm +++ b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: UpdateSet.pm,v 1.25 2009/11/16 14:42:18 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.26 2009/11/22 09:18:55 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -48,6 +48,9 @@ sub pkgname return shift->{name}; } +package OpenBSD::hint2; +our @ISA = qw(OpenBSD::hint); + package OpenBSD::UpdateSet; sub new { @@ -71,6 +74,15 @@ sub add_hints return $self; } +sub add_hints2 +{ + my ($self, @hints) = @_; + for my $h (@hints) { + push(@{$self->{hints}}, OpenBSD::hint2->new($h)); + } + return $self; +} + sub add_older { my $self = shift; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 9df15956009..13b1a84c07b 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.390 2009/11/17 10:54:27 espie Exp $ +# $OpenBSD: pkg_add,v 1.391 2009/11/22 09:18:55 espie Exp $ # # Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org> # @@ -542,46 +542,7 @@ sub install_set return (); } -sub stem2location -{ - my ($repo, $name, $state) = @_; - my $l = $repo->match_locations(OpenBSD::Search::Stem->new($name)); - if (@$l > 1 && !$state->{defines}->{allversions}) { - $l = OpenBSD::Search::FilterLocation->keep_most_recent->filter_locations($l); - } - return $state->choose_location($name, $l); -} - -sub find_truelocations -{ - my ($old, $new, $state) = @_; - - my $cache = {}; - for my $pkgname (@$old) { - if (OpenBSD::PackageName::is_stem($pkgname)) { - my ($h, $path, $repo); - if ($pkgname =~ m/\//o) { - ($repo, $path, $pkgname) = OpenBSD::PackageLocator::path_parse($pkgname); - $h = $repo; - } else { - $h = 'OpenBSD::PackageLocator'; - $path = ""; - } - my $l = stem2location($h, $pkgname, $state); - if (defined $l) { - push(@$new, OpenBSD::UpdateSet->from_location($l)); - } else { - $bad = 1; - } - } else { - if (!defined $cache->{$pkgname}) { - $cache->{$pkgname} = OpenBSD::UpdateSet->create_new($pkgname); - } - push(@$new, $cache->{$pkgname}); - } - } -} our ($opt_a, $opt_A, $opt_P, $opt_Q, $opt_r, $opt_u, $opt_l, $opt_z); @@ -668,8 +629,11 @@ sub inform_user_of_pending_update $state->say("There are some ambiguities. ", "Please run in interactive mode again."); } - $state->say("Running update ", - join(',', map {$_->short_print} @todo2)); + my @t = grep { !$_->{finished} } @todo2; + if (@t > 0) { + $state->say("Running install ", + join(',', map {$_->short_print} @t)); + } } sub process_parameters @@ -688,14 +652,9 @@ sub process_parameters # 1/ match fuzzily against a list if ($opt_l || $opt_z) { - $state->progress->set_header("Looking for packages"); for my $_ (@ARGV) { - my $set = OpenBSD::UpdateSet->new->add_hints($_); - if ($state->updater->process_set($set, $state)) { - push(@todo2, $set); - } + push(@todo2, OpenBSD::UpdateSet->new->add_hints($_)); } - inform_user_of_pending_update($state); # 2/ update existing stuff } elsif ($opt_u) { require OpenBSD::PackageRepository::Installed; @@ -705,32 +664,27 @@ sub process_parameters $state->{full_update} = 1; } my $inst = OpenBSD::PackageRepository::Installed->new; - $state->progress->set_header("Looking for updates"); for my $pkgname (@ARGV) { my $l; if (OpenBSD::PackageName::is_stem($pkgname)) { - $l = stem2location($inst, $pkgname, $state); + $l = $state->updater->stem2location($inst, $pkgname, $state); } else { $l = $inst->find($pkgname, $state->{arch}); } if (!defined $l) { $state->say("Problem finding $pkgname"); } else { - my $set = OpenBSD::UpdateSet->new->add_older(OpenBSD::Handle->from_location($l)); - if ($state->updater->process_set($set, $state)) { - push(@todo2, $set); - } + push(@todo2, OpenBSD::UpdateSet->new->add_older(OpenBSD::Handle->from_location($l))); } } - $state->progress->next; - inform_user_of_pending_update($state); } else { # 3/ actual names - find_truelocations(\@ARGV, \@todo2, $state); - OpenBSD::Add::tag_user_packages(@todo2); + for my $pkgname (@ARGV) { + push(@todo2, OpenBSD::UpdateSet->new->add_hints2($pkgname)); + } } } @@ -759,8 +713,15 @@ sub finish_display framework( sub { + $state->progress->set_header("Looking for packages"); + for my $set (@todo2) { + if (!$state->updater->process_set($set, $state)) { + $set->{finished} = 1; + } + } + $state->progress->next; + inform_user_of_pending_update($state); # This is the actual very small loop that adds all packages - $state->tracker->add_sets(@todo2); while (my $set = shift @todo2) { unshift(@todo2, install_set($set, $state)); } |