diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-10-11 10:53:40 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-10-11 10:53:40 +0000 |
commit | 3d659be558cf580e9fbe9b7a00816331d1fdd3af (patch) | |
tree | a9da6469b0e8abcb2a3c034949b0584bcba03050 /usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | |
parent | 00c191e99cb29c4e54a1348c5587ba9f2d093740 (diff) |
store installed packages in a hash, since we have simple keys for that.
provide newer_names/older_names methods, and a shorter print version of
an updateset (to display during update since it's no longer quite pkg_add -r)
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/UpdateSet.pm')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index 567c5920f9e..3bc63486dbd 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.5 2009/10/10 09:27:30 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.6 2009/10/11 10:53:39 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -164,7 +164,7 @@ package OpenBSD::UpdateSet; sub new { my $class = shift; - return bless {newer => [], older => []}, $class; + return bless {newer => [], older => {}}, $class; } sub add_newer @@ -176,8 +176,10 @@ sub add_newer sub add_older { - my ($self, @handles) = @_; - push(@{$self->{older}}, @handles); + my $self = shift; + for my $h (@_) { + $self->{older}->{$h->{pkgname}} = $h; + } return $self; } @@ -190,7 +192,19 @@ sub newer sub older { my $self = shift; - return @{$self->{older}}; + return values %{$self->{older}}; +} + +sub older_names +{ + my $self = shift; + return keys %{$self->{older}}; +} + +sub newer_names +{ + my $self =shift; + return map {$_->{pkgname}} $self->newer; } sub older_to_do @@ -213,15 +227,28 @@ sub print { my $self = shift; my @l = (); - if (defined $self->{newer}) { - push(@l, "installing", map {$_->{pkgname}} $self->newer); + if ($self->newer > 0) { + push(@l, "installing", $self->newer_names); } - if (defined $self->{older} && @{$self->{older}} > 0) { - push(@l, "deinstalling", map {$_->{pkgname}} $self->older); + if ($self->older > 0) { + push(@l, "deinstalling", $self->older_names); } return join(' ', @l); } +sub short_print +{ + my $self = shift; + my @l = (); + if ($self->older > 0) { + push(@l, join(' ',$self->older_names)); + } + if ($self->newer > 0) { + push(@l, join(' ', $self->newer_names)); + } + return join(' -> ', @l); +} + sub validate_plists { my ($self, $state) = @_; |