summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-11-08 10:46:12 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-11-08 10:46:12 +0000
commit9a8b30600bf602bc541cacc6b1116f32ec60039c (patch)
tree3362f2a3b7ced0db60b83e0e6a59182dc43b7184
parent88ed14ed4437db0fc7aaadb75df641525b2be45a (diff)
add the notion of "hints" to UpdateSet, in order to unify -z/-l handling:
create updatesets with nothing but a hint of what to install. Have Update.pm do the dirty work. More importantly, make Tracker aware of what's going on.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Tracker.pm5
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm26
-rw-r--r--usr.sbin/pkg_add/OpenBSD/UpdateSet.pm17
-rw-r--r--usr.sbin/pkg_add/pkg_add21
4 files changed, 51 insertions, 18 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Tracker.pm b/usr.sbin/pkg_add/OpenBSD/Tracker.pm
index fb67fabb179..117c1190878 100644
--- a/usr.sbin/pkg_add/OpenBSD/Tracker.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Tracker.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Tracker.pm,v 1.5 2009/11/08 09:39:21 espie Exp $
+# $OpenBSD: Tracker.pm,v 1.6 2009/11/08 10:46:11 espie Exp $
#
# Copyright (c) 2009 Marc Espie <espie@openbsd.org>
#
@@ -38,6 +38,9 @@ sub add_set
for my $n ($set->older) {
$self->{to_update}->{$n->pkgname} = $set;
}
+ for my $n ($set->hints) {
+ $self->{to_update}->{$n} = $set;
+ }
return $self;
}
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index b747f851798..e175e103f8e 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.88 2009/10/15 10:48:27 espie Exp $
+# $OpenBSD: Update.pm,v 1.89 2009/11/08 10:46:11 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -135,4 +135,28 @@ sub process_handle
}
}
+sub process_hint
+{
+ my ($self, $set, $hint, $state) = @_;
+
+ my $l;
+ my $k = OpenBSD::Search::FilterLocation->keep_most_recent;
+ # first try to find us exactly
+
+ $state->progress->message("Looking for $hint");
+ $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Exact->new($hint), $k);
+ if (@$l == 0) {
+ my $t = $hint;
+ $t =~ s/\-\d([^-]*)\-?/--/;
+ $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Stem->new($t), $k);
+ }
+ my $r = $state->choose_location($hint, $l);
+ if (defined $r) {
+ $self->add_updateset($set, undef, $r);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm
index 6f313723168..8fa80d0aeec 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.11 2009/11/04 16:50:02 espie Exp $
+# $OpenBSD: UpdateSet.pm,v 1.12 2009/11/08 10:46:11 espie Exp $
#
# Copyright (c) 2007 Marc Espie <espie@openbsd.org>
#
@@ -117,7 +117,7 @@ package OpenBSD::UpdateSet;
sub new
{
my $class = shift;
- return bless {newer => [], older => {}}, $class;
+ return bless {newer => [], older => {}, hints => []}, $class;
}
sub add_newer
@@ -127,6 +127,13 @@ sub add_newer
return $self;
}
+sub add_hints
+{
+ my ($self, @hints) = @_;
+ push(@{$self->{hints}}, @hints);
+ return $self;
+}
+
sub add_older
{
my $self = shift;
@@ -148,6 +155,12 @@ sub older
return values %{$self->{older}};
}
+sub hints
+{
+ my $self =shift;
+ return @{$self->{hints}};
+}
+
sub older_names
{
my $self = shift;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 67ddee7daec..9d2a94f82f9 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.370 2009/11/08 09:39:21 espie Exp $
+# $OpenBSD: pkg_add,v 1.371 2009/11/08 10:46:11 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -678,21 +678,14 @@ if ($opt_l) {
# three cases:
# 1/ match fuzzily against a list
if ($opt_l || $opt_z) {
- my $k = OpenBSD::Search::FilterLocation->keep_most_recent;
+ require OpenBSD::Update;
+ my $updater = OpenBSD::Update->new;
+
$state->progress->set_header("Looking for packages");
for my $_ (@ARGV) {
- my $l;
- # first try to find us exactly
- $state->progress->message("Looking for $_");
- $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Exact->new($_), $k);
- if (@$l == 0) {
- my $t = $_;
- $t =~ s/\-\d([^-]*)\-?/--/;
- $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Stem->new($t), $k);
- }
- my $r = $state->choose_location($_, $l);
- if (defined $r) {
- push(@todo2, OpenBSD::UpdateSet->from_location($r));
+ my $set = OpenBSD::UpdateSet->new->add_hints($_);
+ if ($updater->process_hint($set, $_, $state)) {
+ push(@todo2, $set);
}
}
# 2/ update existing stuff