summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2010-06-18 09:01:39 +0000
committerMarc Espie <espie@cvs.openbsd.org>2010-06-18 09:01:39 +0000
commita5e0688e8922001a21e5024bda77f7cd3cc03a83 (patch)
treec57bc9f1dbd7a4e17d106016357c42add84b0a83 /usr.sbin/pkg_add
parent2e5f1c66c8d48de25f7c9637a5ced12b2dfe0447 (diff)
buglet: Log object needs a printer to run f().
introduce for_list() iterator in ProgressMeter and use it
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgCheck.pm17
-rw-r--r--usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm17
2 files changed, 23 insertions, 11 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm b/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm
index 67d33b9282b..0a157669ab7 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgCheck.pm
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgCheck.pm,v 1.17 2010/06/15 08:53:55 espie Exp $
+# $OpenBSD: PkgCheck.pm,v 1.18 2010/06/18 09:01:38 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -221,7 +221,7 @@ use OpenBSD::Log;
sub init
{
my $self = shift;
- $self->{l} = OpenBSD::Log->new;
+ $self->{l} = OpenBSD::Log->new($self);
$self->SUPER::init;
}
@@ -441,14 +441,11 @@ sub for_all_packages
{
my ($self, $state, $l, $msg, $code) = @_;
- my $total = scalar @$l;
- $state->progress->set_header($msg);
- my $i = 0;
- for my $name (@$l) {
- $state->progress->show(++$i, $total);
- next if $state->{removed}{$name};
- &$code($name);
- }
+ $state->progress->for_list($msg, $l,
+ sub {
+ next if $state->{removed}{$_[0]};
+ &$code;
+ });
}
sub sanity_check
diff --git a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
index 6baf91e1b17..3319f68a6ba 100644
--- a/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
+++ b/usr.sbin/pkg_add/OpenBSD/ProgressMeter.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: ProgressMeter.pm,v 1.33 2010/06/05 12:01:08 espie Exp $
+# $OpenBSD: ProgressMeter.pm,v 1.34 2010/06/18 09:01:38 espie Exp $
#
# Copyright (c) 2010 Marc Espie <espie@openbsd.org>
#
@@ -46,6 +46,21 @@ sub errprint
print STDERR @_;
}
+sub for_list
+{
+ my ($self, $msg, $l, $code) = @_;
+ if (defined $msg) {
+ $self->set_header($msg);
+ }
+ my $total = scalar @$l;
+ my $i = 0;
+ for my $e (@$l) {
+ $self->show(++$i, $total);
+ &$code($e);
+ }
+ $self->next;
+}
+
# stub class when no actual progressmeter that still prints out.
package OpenBSD::ProgressMeter::Stub;
our @ISA = qw(OpenBSD::ProgressMeter);