diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-06-01 14:58:30 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-06-01 14:58:30 +0000 |
commit | 34efd479fa8bad945ccf900ff7b2ea62520b5ab9 (patch) | |
tree | 45fa87d5e13357c168aceffa96b66199b0fd125e /usr.sbin/pkg_add/OpenBSD/Vstat.pm | |
parent | 323bb16b2bd94d254e8211d526fa04629fb1aec7 (diff) |
refactor ProgressMeter code to create objects, put these into state.
Create a common state class for delete and add, put the progressmeter
creation in there.
neat effect: we don't have a progressmeter, we use a stub class instead
and *never* pull the code in at all.
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD/Vstat.pm')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Vstat.pm | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Vstat.pm b/usr.sbin/pkg_add/OpenBSD/Vstat.pm index 961d19c6cd0..8d805644cc6 100644 --- a/usr.sbin/pkg_add/OpenBSD/Vstat.pm +++ b/usr.sbin/pkg_add/OpenBSD/Vstat.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Vstat.pm,v 1.30 2007/05/30 14:04:51 espie Exp $ +# $OpenBSD: Vstat.pm,v 1.31 2007/06/01 14:58:29 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -267,6 +267,50 @@ sub cleanup OpenBSD::SharedItems::cleanup($self, $state); } +package OpenBSD::pkg_foo::State; +use OpenBSD::Error; +our @ISA=(qw(OpenBSD::Error)); + +sub progress +{ + my $self = shift; + return $self->{progressmeter}; +} + +sub setup_progressmeter +{ + my ($self, $opt_x) = @_; + if (!$opt_x && !$self->{beverbose}) { + require OpenBSD::ProgressMeter; + $self->{progressmeter} = OpenBSD::ProgressMeter->new; + } else { + $self->{progressmeter} = bless {}, "OpenBSD::StubProgress"; + } +} + +sub check_root +{ + my $state = shift; + if ($< && !$state->{forced}->{nonroot}) { + if ($state->{not}) { + Warn "$0 should be run as root\n"; + } else { + Fatal "$0 must be run as root"; + } + } +} + +package OpenBSD::StubProgress; +sub clear {} + +sub show {} + +sub message {} + +sub next {} + +sub set_header {} + # fairly non-descriptive name. Used to store various package information # during installs and updates. package OpenBSD::Handle; @@ -406,11 +450,10 @@ sub mark_progress package OpenBSD::PackingElement::FileBase; sub mark_progress { - my ($self, $donesize, $totsize) = @_; + my ($self, $progress, $donesize, $totsize) = @_; return unless defined $self->{size}; - require OpenBSD::ProgressMeter; $$donesize += $self->{size}; - OpenBSD::ProgressMeter::show($$donesize, $totsize); + $progress->show($$donesize, $totsize); } 1; |