diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2010-01-10 11:31:09 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2010-01-10 11:31:09 +0000 |
commit | 4b53a42101b57990a39db6675eb7421e306e8516 (patch) | |
tree | 7bdb65c8776ca865082bcb63b1790f32043d1d9e /usr.sbin | |
parent | b7c3e288a7dc04a9a101a084f6cc3b9dcf1aa0b8 (diff) |
pull the signature comparison code into its own file.
add comparison functions to Packagenames that return undef when it matters.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageName.pm | 11 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 19 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingList.pm | 55 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Signature.pm | 161 |
5 files changed, 177 insertions, 72 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile index 37f6847984a..f3791fe4c5a 100644 --- a/usr.sbin/pkg_add/Makefile +++ b/usr.sbin/pkg_add/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.56 2009/12/26 17:00:49 espie Exp $ +# $OpenBSD: Makefile,v 1.57 2010/01/10 11:31:08 espie Exp $ .include <bsd.own.mk> @@ -43,6 +43,7 @@ PACKAGES= \ OpenBSD/Replace.pm \ OpenBSD/RequiredBy.pm \ OpenBSD/Search.pm \ + OpenBSD/Signature.pm \ OpenBSD/SharedItems.pm \ OpenBSD/SharedLibs.pm \ OpenBSD/Subst.pm \ diff --git a/usr.sbin/pkg_add/OpenBSD/PackageName.pm b/usr.sbin/pkg_add/OpenBSD/PackageName.pm index b5aea42cde5..8a100d91076 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageName.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageName.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageName.pm,v 1.39 2010/01/09 17:42:25 espie Exp $ +# $OpenBSD: PackageName.pm,v 1.40 2010/01/10 11:31:08 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -455,4 +455,13 @@ sub to_pattern return join('-', $o->{stem}, '*', $o->flavor_string); } +sub compare +{ + my ($a, $b) = @_; + if ($a->{stem} ne $b->{stem} || $a->flavor_string ne $b->flavor_string) { + return undef; + } + return $a->{version}->compare($b->{version}); +} + 1; diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index ab66cc72b44..3df5c079abf 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingElement.pm,v 1.171 2010/01/09 17:44:21 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.172 2010/01/10 11:31:08 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -152,7 +152,6 @@ sub IsFile() { 0 } sub NoDuplicateNames() { 0 } -sub signature {} sub copy_shallow_if { @@ -916,12 +915,6 @@ sub stringize (qw(pkgpath pattern def))); } -sub signature -{ - my ($self, $hash) = @_; - $hash->{$self->{pkgpath}} = OpenBSD::PackageName->from_string($self->{def}); -} - OpenBSD::Auto::cache(spec, sub { require OpenBSD::Search; @@ -958,16 +951,6 @@ sub add_digest &OpenBSD::PackingElement::FileBase::add_digest; } -sub signature -{ - my ($self, $hash) = @_; - require OpenBSD::SharedLibs; - - if (my ($stem, $major, $minor) = OpenBSD::SharedLibs::parse_spec($self->name)) { - $hash->{$stem} = OpenBSD::LibrarySpec->new($stem, $major, $minor); - } -} - package OpenBSD::PackingElement::PkgPath; our @ISA=qw(OpenBSD::PackingElement::Meta); diff --git a/usr.sbin/pkg_add/OpenBSD/PackingList.pm b/usr.sbin/pkg_add/OpenBSD/PackingList.pm index b1f80c28890..6d666add5b7 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingList.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingList.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingList.pm,v 1.100 2010/01/09 17:44:21 espie Exp $ +# $OpenBSD: PackingList.pm,v 1.101 2010/01/10 11:31:08 espie Exp $ # # Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org> # @@ -568,58 +568,9 @@ sub AUTOLOAD sub signature { my $self = shift; - if ($self->has('always-update')) { - my $s; - open my $fh, '>', \$s; - $self->write_no_sig($fh); - close $fh; - return OpenBSD::PackingList::FullSignature->new($self->pkgname, - $s); - } else { - my $k = {}; - $self->visit('signature', $k); - return OpenBSD::PackingList::Signature->new($self->pkgname, $k); - } -} - -package OpenBSD::PackingList::Signature; -sub new -{ - my ($class, $pkgname, $extra) = @_; - bless { name => $pkgname, extra => $extra }, $class; -} - -sub string -{ - my $self = shift; - return join(',', $self->{name}, sort map {$_->to_string} values %{$self->{extra}}); -} - -sub compare -{ - my ($a, $b) = @_; - return $a->string cmp $b->string; -} - -package OpenBSD::PackingList::FullSignature; -our @ISA=qw(OpenBSD::PackingList::Signature); - -sub string -{ - my $self = shift; - return $self->{extra}; -} -package OpenBSD::LibrarySpec; -sub new -{ - my ($class, $stem, $major, $minor) = @_; - bless {stem => $stem, major => $major, minor => $minor}, $class; + require OpenBSD::Signature; + return OpenBSD::Signature->from_plist($self); } -sub to_string -{ - my $self = shift; - return join('.', $self->{stem}, $self->{major}, $self->{minor}); -} 1; diff --git a/usr.sbin/pkg_add/OpenBSD/Signature.pm b/usr.sbin/pkg_add/OpenBSD/Signature.pm new file mode 100644 index 00000000000..5d7a37a449d --- /dev/null +++ b/usr.sbin/pkg_add/OpenBSD/Signature.pm @@ -0,0 +1,161 @@ +# ex:ts=8 sw=4: +# $OpenBSD: Signature.pm,v 1.1 2010/01/10 11:31:08 espie Exp $ +# +# Copyright (c) 2010 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +use strict; +use warnings; + +package OpenBSD::PackingElement; +sub signature {} + +package OpenBSD::PackingElement::Dependency; +sub signature +{ + my ($self, $hash) = @_; + $hash->{$self->{pkgpath}} = OpenBSD::PackageName->from_string($self->{def}); +} + +package OpenBSD::PackingElement::Wantlib; +sub signature +{ + my ($self, $hash) = @_; + require OpenBSD::SharedLibs; + + my ($stem, $major, $minor) = OpenBSD::SharedLibs::parse_spec($self->name); + if (defined $stem) { + $hash->{$stem} = OpenBSD::LibrarySpec->new($stem, + $major, $minor); + } +} + +package OpenBSD::Signature; +sub from_plist +{ + my ($class, $plist) = @_; + + if ($plist->has('always-update')) { + my $s; + open my $fh, '>', \$s; + $plist->write_no_sig($fh); + close $fh; + return $class->always->new($plist->pkgname, $s); + } else { + my $k = {}; + $plist->visit('signature', $k); + return $class->new($plist->pkgname, $k); + } +} + +sub always +{ + return "OpenBSD::Signature::Full"; +} + +sub new +{ + my ($class, $pkgname, $extra) = @_; + bless { name => $pkgname, extra => $extra }, $class; +} + +sub string +{ + my $self = shift; + return join(',', $self->{name}, sort map {$_->to_string} values %{$self->{extra}}); +} + +sub compare +{ + my ($a, $b) = @_; + + if ($a->{name} eq $b->{name}) { + return $b->revert_compare($a); + } else { + return OpenBSD::PackageName->from_string($a->{name})->compare(OpenBSD::PackageName->from_string($b->{name})); + } +} + +sub revert_compare +{ + my ($b, $a) = @_; + + my $awins = 0; + my $bwins = 0; + while (my ($k, $v) = each %{$a->{extra}}) { + next if !defined $b->{extra}{$k}; + my $r = $v->compare($b->{extra}{$k}); + if ($r > 0) { + $awins++; + } elsif ($r < 0) { + $bwins++; + } + } + if ($awins == 0) { + return -$bwins; + } elsif ($bwins == 0) { + return $awins; + } else { + return undef; + } +} + +package OpenBSD::Signature::Full; +our @ISA=qw(OpenBSD::Signature); + +sub string +{ + my $self = shift; + return $self->{extra}; +} + +sub revert_compare +{ + my ($b, $a) = @_; + return $a->string cmp $b->string; +} + +sub compare +{ + my ($a, $b) = @_; + return $a->string cmp $b->string; +} + +package OpenBSD::LibrarySpec; +sub new +{ + my ($class, $stem, $major, $minor) = @_; + bless {stem => $stem, major => $major, minor => $minor}, $class; +} + +sub to_string +{ + my $self = shift; + return join('.', $self->{stem}, $self->{major}, $self->{minor}); +} + +sub compare +{ + my ($a, $b) = @_; + + if ($a->{stem} ne $b->{stem}) { + return undef; + } + if ($a->{major} != $b->{major}) { + return $a->{major} <=> $b->{major}; + } + return $a->{minor} <=> $b->{minor}; +} + +1; |