diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-05-14 11:22:01 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-05-14 11:22:01 +0000 |
commit | 8131554814c6ddf6df3c93366f96d307a497458c (patch) | |
tree | ae2fc65691acd83e90813bf35d46aa4cc0654a51 /usr.sbin | |
parent | 720febe1bcd1646d4cd6850bd15b98c0df0a1324 (diff) |
redo search filters as real objects. Accordingly, rename match_list to
filter.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Dependencies.pm | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm | 13 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PkgCfl.pm | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Replace.pm | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Search.pm | 27 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Update.pm | 18 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 4 |
7 files changed, 51 insertions, 25 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm index 5b9ff23a887..7a11c4569fb 100644 --- a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm +++ b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Dependencies.pm,v 1.26 2007/05/14 11:02:14 espie Exp $ +# $OpenBSD: Dependencies.pm,v 1.27 2007/05/14 11:22:00 espie Exp $ # # Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org> # @@ -29,7 +29,7 @@ use OpenBSD::Interactive; sub find_candidate { my $spec = shift; - my @candidates = $spec->match_list(@_); + my @candidates = $spec->filter(@_); if (@candidates >= 1) { return $candidates[0]; } else { diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm index 2aa06cf45f0..4fc3705d362 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository/Installed.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Installed.pm,v 1.4 2007/05/14 10:43:45 espie Exp $ +# $OpenBSD: Installed.pm,v 1.5 2007/05/14 11:22:00 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -28,12 +28,13 @@ package OpenBSD::PackageRepositoryBase; sub match { - my ($self, $search, $filter) = @_; - if (defined $filter) { - return &$filter($search->match($self)); - } else { - return $search->match($self); + my ($self, $search, @filters) = @_; + my @l = $search->match($self); + while (my $filter = (shift @filters)) { + last if @l == 0; # don't bother filtering empty list + @l = $filter->filter(@l); } + return @l; } package OpenBSD::PackageRepository::Installed; diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm index 5830dbdc4e8..eebf9c6faa2 100644 --- a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm +++ b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PkgCfl.pm,v 1.21 2007/05/14 11:02:15 espie Exp $ +# $OpenBSD: PkgCfl.pm,v 1.22 2007/05/14 11:22:00 espie Exp $ # # Copyright (c) 2003-2005 Marc Espie <espie@openbsd.org> # @@ -54,7 +54,7 @@ sub conflicts_with my ($self, @pkgnames) = @_; my @l = (); for my $cfl (@$self) { - push(@l, $cfl->match_list(@pkgnames)); + push(@l, $cfl->filter(@pkgnames)); } return @l; } diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm index 1a25b358c2b..1125db54f7f 100644 --- a/usr.sbin/pkg_add/OpenBSD/Replace.pm +++ b/usr.sbin/pkg_add/OpenBSD/Replace.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Replace.pm,v 1.11 2007/05/14 10:43:45 espie Exp $ +# $OpenBSD: Replace.pm,v 1.12 2007/05/14 11:22:00 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -159,9 +159,9 @@ sub check_replacement_spec my ($self, $state, $wanting, $toreplace, $replacement) = @_; # nothing to validate if old dependency doesn't concern us. - return unless $self->spec->match_list($toreplace); + return unless $self->spec->filter($toreplace); # nothing to do if new dependency just matches - return if $self->spec->match_list($replacement); + return if $self->spec->filter($replacement); if ($state->{forced}->{updatedepends}) { Warn "Forward dependency of $wanting on $toreplace doesn't match $replacement, forcing it\n"; diff --git a/usr.sbin/pkg_add/OpenBSD/Search.pm b/usr.sbin/pkg_add/OpenBSD/Search.pm index bfc336d9af0..4f5a549a514 100644 --- a/usr.sbin/pkg_add/OpenBSD/Search.pm +++ b/usr.sbin/pkg_add/OpenBSD/Search.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Search.pm,v 1.1 2007/05/14 11:02:15 espie Exp $ +# $OpenBSD: Search.pm,v 1.2 2007/05/14 11:22:00 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -38,7 +38,7 @@ sub match return $self->match_ref($o->list); } -sub match_list +sub filter { my ($self, @list) = @_; return $self->match_ref(\@list); @@ -84,5 +84,28 @@ sub match return $o->stemlist->find_partial($self->{stem}); } +package OpenBSD::Search::Filter; +our @ISA=(qw(OpenBSD::Search)); + +sub new +{ + my ($class, $code) = @_; + + return bless {code => $code}, $class; +} + +sub filter +{ + my ($self, @l) = @_; + return &{$self->{code}}(@l); +} + +sub keep_most_recent +{ + my $class = shift; + require OpenBSD::PackageName; + + return $class->new(\&OpenBSD::PackageName::keep_most_recent); +} 1; diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm index b9da98c7916..023fd165487 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.76 2007/05/14 10:53:31 espie Exp $ +# $OpenBSD: Update.pm,v 1.77 2007/05/14 11:22:00 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -63,19 +63,21 @@ sub process_package print "Not updating $pkgname, remember to clean it\n"; return; } - my $stem = OpenBSD::Search::Stem->split($pkgname); + my @search = (); + push(@search, OpenBSD::Search::Stem->split($pkgname)); + if (!$state->{forced}->{allversions}) { + push(@search, OpenBSD::Search::Filter->keep_most_recent); + } my $found; my $plist; - my $filter = sub { + push(@search, OpenBSD::Search::Filter->new( + sub { my @l = @_; if (@l == 0) { return @l; } - if (@l > 1 && !$state->{forced}->{allversions}) { - @l = OpenBSD::PackageName::keep_most_recent(@l); - } if (@l == 1 && $state->{forced}->{pkgpath}) { return @l; } @@ -116,10 +118,10 @@ sub process_package } } return @l2; - }; + })); - my @l = OpenBSD::PackageLocator->match($stem, $filter); + my @l = OpenBSD::PackageLocator->match(@search); if (@l == 0) { $self->add2cant($pkgname); return; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 801eda22705..d0afbb0ee1a 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.244 2007/05/14 11:02:14 espie Exp $ +# $OpenBSD: pkg_add,v 1.245 2007/05/14 11:22:00 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -331,7 +331,7 @@ sub really_add($$) OpenBSD::ProgressMeter::set_header($op->pkgname." (deleting)"); $state->set_pkgname($op->pkgname); require OpenBSD::Search; - if (OpenBSD::Search::PkgSpec->new("mozilla-thunderbird-<=1.0.2p0")->match_list($op->pkgname)) { + if (OpenBSD::Search::PkgSpec->new("mozilla-thunderbird-<=1.0.2p0")->filter($op->pkgname)) { thunderbird_special_case($plist); } require OpenBSD::Delete; |