diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-11-16 12:20:33 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-11-16 12:20:33 +0000 |
commit | 97f94b34e5942cdb852a2154abffaa3815d35bfb (patch) | |
tree | 03f1d286f8ad7887bf460b6ee517d1f4e52b382e /usr.sbin | |
parent | 12f67d394eebe8fd0732202a8a08e33aafd6bdfd (diff) |
start pulling all the code that's the same between pkg_add and pkg_delete
into a common AddDelete package... lots of identical options and handling,
actually...
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/AddDelete.pm | 326 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 239 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 93 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_delete | 104 |
5 files changed, 367 insertions, 398 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile index 3f80f3022f7..c5fe685b2ba 100644 --- a/usr.sbin/pkg_add/Makefile +++ b/usr.sbin/pkg_add/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.54 2009/10/15 18:17:18 espie Exp $ +# $OpenBSD: Makefile,v 1.55 2009/11/16 12:20:32 espie Exp $ .include <bsd.own.mk> @@ -12,6 +12,7 @@ POD2MAN=/usr/bin/pod2man PACKAGES= \ OpenBSD/Add.pm \ + OpenBSD/AddDelete.pm \ OpenBSD/ArcCheck.pm \ OpenBSD/CollisionReport.pm \ OpenBSD/Delete.pm \ diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm new file mode 100644 index 00000000000..75b245e5920 --- /dev/null +++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm @@ -0,0 +1,326 @@ +# ex:ts=8 sw=4: +# $OpenBSD: AddDelete.pm,v 1.1 2009/11/16 12:20:32 espie Exp $ +# +# Copyright (c) 2007-2009 Marc Espie <espie@openbsd.org> +# + +use strict; +use warnings; + +# common framework, let's place most everything in there +package main; +our $not; + +package OpenBSD::AddDelete; +use OpenBSD::Getopt; +use OpenBSD::Error; +use OpenBSD::Paths; + +our $bad = 0; +our %defines = (); +our $state; + +our ($opt_n, $opt_x, $opt_v, $opt_B, $opt_L, $opt_i, $opt_q, $opt_c, $opt_I); +$opt_v = 0; + +sub setup_state +{ + lock_db($opt_n) unless $state->{defines}->{nolock}; + $state->setup_progressmeter($opt_x); + $state->check_root; +} + +sub handle_options +{ + my ($opt_string, $hash) = @_; + $hash->{h} = sub { Usage(); }; + $hash->{f} = $hash->{F} = sub { + for my $o (split /\,/o, shift) { + $defines{$o} = 1; + } + }; + try { + getopts('hciInqvxB:f:F:L:'.$opt_string, $hash); + } catchall { + Usage($_); + }; + + $opt_L = OpenBSD::Paths->localbase unless defined $opt_L; + + $state->{recorder} = OpenBSD::SharedItemsRecorder->new; + $state->{not} = $opt_n; + # XXX RequiredBy + $main::not = $opt_n; + $state->{defines} = \%defines; + $state->{very_verbose} = $opt_v >= 2; + $state->{verbose} = $opt_v; + $state->{interactive} = $opt_i; + $state->{beverbose} = $opt_n || ($opt_v >= 2); + $state->{localbase} = $opt_L; + $state->{quick} = $opt_q; + $state->{extra} = $opt_c; + $state->{dont_run_scripts} = $opt_I; +} + +sub do_the_main_work +{ + my $code = shift; + + if ($bad) { + exit(1); + } + + my $handler = sub { my $sig = shift; die "Caught SIG$sig"; }; + local $SIG{'INT'} = $handler; + local $SIG{'QUIT'} = $handler; + local $SIG{'HUP'} = $handler; + local $SIG{'KILL'} = $handler; + local $SIG{'TERM'} = $handler; + + if ($state->{defines}->{debug}) { + &$code; + } else { + eval { &$code; }; + } + my $dielater = $@; + # cleanup various things + $state->{recorder}->cleanup($state); + OpenBSD::PackingElement::Lib::ensure_ldconfig($state); + OpenBSD::PackingElement::Fontdir::finish_fontdirs($state); + if ($state->{beverbose}) { + OpenBSD::Vstat::tally(); + } + $state->progress->clear; + $state->log->dump; + return $dielater; +} + +package OpenBSD::SharedItemsRecorder; +sub new +{ + my $class = shift; + return bless {}, $class; +} + +sub is_empty +{ + my $self = shift; + return !(defined $self->{dirs} or defined $self->{users} or + defined $self->{groups}); +} + +sub cleanup +{ + my ($self, $state) = @_; + return if $self->is_empty or $state->{not}; + + require OpenBSD::SharedItems; + OpenBSD::SharedItems::cleanup($self, $state); +} + +package OpenBSD::Log; +use OpenBSD::Error; +our @ISA = qw(OpenBSD::Error); + +sub set_context +{ + &OpenBSD::Error::set_pkgname; +} + +sub dump +{ + &OpenBSD::Error::delayed_output; +} + + +package OpenBSD::UI; +use OpenBSD::Error; + +sub new +{ + my $class = shift; + my $o = bless {}, $class; + $o->init(@_); + return $o; +} + +sub init +{ + my $self = shift; + $self->{l} = OpenBSD::Log->new; + $self->{progressmeter} = bless {}, "OpenBSD::StubProgress"; +} + +sub log +{ + my $self = shift; + if (@_ == 0) { + return $self->{l}; + } else { + $self->{l}->print(@_); + } +} + +sub print +{ + my $self = shift; + $self->progress->print(@_); +} + +sub say +{ + my $self = shift; + $self->progress->print(@_, "\n"); +} + +sub errprint +{ + my $self = shift; + $self->progress->errprint(@_); +} + +sub errsay +{ + my $self = shift; + $self->progress->errprint(@_, "\n"); +} + +sub progress +{ + my $self = shift; + return $self->{progressmeter}; +} + +sub vsystem +{ + my $self = shift; + $self->progress->clear; + OpenBSD::Error::VSystem($self->{very_verbose}, @_); +} + +sub system +{ + my $self = shift; + $self->progress->clear; + OpenBSD::Error::System(@_); +} + +sub unlink +{ + my $self = shift; + $self->progress->clear; + OpenBSD::Error::Unlink(@_); +} + +# we always have a progressmeter we can print to... +sub setup_progressmeter +{ + my ($self, $opt_x) = @_; + if (!$opt_x && !$self->{beverbose}) { + require OpenBSD::ProgressMeter; + $self->{progressmeter} = OpenBSD::ProgressMeter->new; + } +} + +sub check_root +{ + my $state = shift; + if ($< && !$state->{defines}->{nonroot}) { + if ($state->{not}) { + $state->errsay("$0 should be run as root"); + } else { + Fatal "$0 must be run as root"; + } + } +} + +sub choose_location +{ + my ($state, $name, $list) = @_; + if (@$list == 0) { + $state->say("Can't find $name"); + return undef; + } elsif (@$list == 1) { + return $list->[0]; + } + + my %h = map {($_->name, $_)} @$list; + if ($state->{interactive}) { + require OpenBSD::Interactive; + + $h{'<None>'} = undef; + $state->progress->clear; + my $result = OpenBSD::Interactive::ask_list("Ambiguous: choose package for $name", 1, sort keys %h); + return $h{$result}; + } else { + $state->say("Ambiguous: $name could be ", join(' ', keys %h)); + return undef; + } +} + +# stub class when no actual progressmeter that still prints out. +package OpenBSD::StubProgress; +sub clear {} + +sub show {} + +sub message {} + +sub next {} + +sub set_header {} + +sub print +{ + shift; + print @_; +} + +sub errprint +{ + shift; + print STDERR @_; +} + +package OpenBSD::PackingList; +sub compute_size +{ + my $plist = shift; + my $totsize = 0; + $plist->visit('compute_size', \$totsize); + $totsize = 1 if $totsize == 0; + $plist->{totsize} = $totsize; +} + +package OpenBSD::PackingElement; +sub mark_progress +{ +} + +sub compute_size +{ +} + +package OpenBSD::PackingElement::FileBase; +sub mark_progress +{ + my ($self, $progress, $donesize, $totsize) = @_; + return unless defined $self->{size}; + $$donesize += $self->{size}; + $progress->show($$donesize, $totsize); +} + +sub compute_size +{ + my ($self, $totsize) = @_; + + $$totsize += $self->{size} if defined $self->{size}; +} + +package OpenBSD::PackingElement::Sample; +sub compute_size +{ + &OpenBSD::PackingElement::FileBase::compute_size; +} + +1; diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index 52a40a3b57a..f129e3b9ea0 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.23 2009/11/11 13:00:40 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.24 2009/11/16 12:20:32 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -16,199 +16,6 @@ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# these things don't really live here, they're just stuff that's shared -# between pkg_add and pkg_delete, so to avoid yes another header... - -use strict; -use warnings; - -package OpenBSD::SharedItemsRecorder; -sub new -{ - my $class = shift; - return bless {}, $class; -} - -sub is_empty -{ - my $self = shift; - return !(defined $self->{dirs} or defined $self->{users} or - defined $self->{groups}); -} - -sub cleanup -{ - my ($self, $state) = @_; - return if $self->is_empty or $state->{not}; - - require OpenBSD::SharedItems; - OpenBSD::SharedItems::cleanup($self, $state); -} - -package OpenBSD::Log; -use OpenBSD::Error; -our @ISA = qw(OpenBSD::Error); - -sub set_context -{ - &OpenBSD::Error::set_pkgname; -} - -sub dump -{ - &OpenBSD::Error::delayed_output; -} - - -package OpenBSD::pkg_foo::State; -use OpenBSD::Error; - -sub new -{ - my $class = shift; - my $o = bless {}, $class; - $o->init(@_); - return $o; -} - -sub init -{ - my $self = shift; - $self->{l} = OpenBSD::Log->new; - $self->{progressmeter} = bless {}, "OpenBSD::StubProgress"; -} - -sub log -{ - my $self = shift; - if (@_ == 0) { - return $self->{l}; - } else { - $self->{l}->print(@_); - } -} - -sub print -{ - my $self = shift; - $self->progress->print(@_); -} - -sub say -{ - my $self = shift; - $self->progress->print(@_, "\n"); -} - -sub errprint -{ - my $self = shift; - $self->progress->errprint(@_); -} - -sub errsay -{ - my $self = shift; - $self->progress->errprint(@_, "\n"); -} - -sub progress -{ - my $self = shift; - return $self->{progressmeter}; -} - -sub vsystem -{ - my $self = shift; - $self->progress->clear; - OpenBSD::Error::VSystem($self->{very_verbose}, @_); -} - -sub system -{ - my $self = shift; - $self->progress->clear; - OpenBSD::Error::System(@_); -} - -sub unlink -{ - my $self = shift; - $self->progress->clear; - OpenBSD::Error::Unlink(@_); -} - -# we always have a progressmeter we can print to... -sub setup_progressmeter -{ - my ($self, $opt_x) = @_; - if (!$opt_x && !$self->{beverbose}) { - require OpenBSD::ProgressMeter; - $self->{progressmeter} = OpenBSD::ProgressMeter->new; - } -} - -sub check_root -{ - my $state = shift; - if ($< && !$state->{defines}->{nonroot}) { - if ($state->{not}) { - $state->errsay("$0 should be run as root"); - } else { - Fatal "$0 must be run as root"; - } - } -} - -sub choose_location -{ - my ($state, $name, $list) = @_; - if (@$list == 0) { - $state->say("Can't find $name"); - return undef; - } elsif (@$list == 1) { - return $list->[0]; - } - - my %h = map {($_->name, $_)} @$list; - if ($state->{interactive}) { - require OpenBSD::Interactive; - - $h{'<None>'} = undef; - $state->progress->clear; - my $result = OpenBSD::Interactive::ask_list("Ambiguous: choose package for $name", 1, sort keys %h); - return $h{$result}; - } else { - $state->say("Ambiguous: $name could be ", join(' ', keys %h)); - return undef; - } -} - -# stub class when no actual progressmeter that still prints out. -package OpenBSD::StubProgress; -sub clear {} - -sub show {} - -sub message {} - -sub next {} - -sub set_header {} - -sub print -{ - shift; - print @_; -} - -sub errprint -{ - shift; - print STDERR @_; -} - # an UpdateSet is a list of packages to remove/install. # it contains three things: # -> a list of older packages to remove (installed locations) @@ -225,6 +32,9 @@ sub errprint # Normal UpdateSets contain one newer package at most. # Bigger UpdateSets can be created through the merge operation, which # will be used only when necessary. +use strict; +use warnings; + package OpenBSD::UpdateSet; sub new { @@ -408,45 +218,4 @@ sub merge return $self; } -package OpenBSD::PackingList; -sub compute_size -{ - my $plist = shift; - my $totsize = 0; - $plist->visit('compute_size', \$totsize); - $totsize = 1 if $totsize == 0; - $plist->{totsize} = $totsize; -} - -package OpenBSD::PackingElement; -sub mark_progress -{ -} - -sub compute_size -{ -} - -package OpenBSD::PackingElement::FileBase; -sub mark_progress -{ - my ($self, $progress, $donesize, $totsize) = @_; - return unless defined $self->{size}; - $$donesize += $self->{size}; - $progress->show($$donesize, $totsize); -} - -sub compute_size -{ - my ($self, $totsize) = @_; - - $$totsize += $self->{size} if defined $self->{size}; -} - -package OpenBSD::PackingElement::Sample; -sub compute_size -{ - &OpenBSD::PackingElement::FileBase::compute_size; -} - 1; diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 8599d7717b9..e1f4c877419 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.382 2009/11/14 10:47:16 espie Exp $ +# $OpenBSD: pkg_add,v 1.383 2009/11/16 12:20:32 espie Exp $ # # Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org> # @@ -20,6 +20,9 @@ use strict; use warnings; +use OpenBSD::AddDelete; + +package OpenBSD::AddDelete; use OpenBSD::Dependencies; use OpenBSD::PackingList; use OpenBSD::PackageInfo; @@ -27,19 +30,13 @@ use OpenBSD::PackageLocator; use OpenBSD::PackageName; use OpenBSD::PkgCfl; use OpenBSD::Vstat; -use OpenBSD::Getopt; -use OpenBSD::Error; use OpenBSD::Interactive; use OpenBSD::Add; use OpenBSD::SharedLibs; -use OpenBSD::Paths; use OpenBSD::UpdateSet; use OpenBSD::Handle; -my $bad = 0; - -our %defines = (); -our $not; +our ($state, %defines, $bad, $opt_B); package OpenBSD::PackingList; @@ -66,7 +63,7 @@ sub has_new_sig } package OpenBSD::pkg_add::State; -our @ISA=(qw(OpenBSD::pkg_foo::State)); +our @ISA=(qw(OpenBSD::UI)); # one-level dependencies tree, for nicer printouts sub build_deptree @@ -267,7 +264,7 @@ sub can_install return 1; } -package main; +package OpenBSD::AddDelete; sub failed_message { @@ -591,36 +588,16 @@ sub find_truelocations set_usage('pkg_add [-acIinqruvxz] [-A arch] [-B pkg-destdir] [-F keywords]', '[-L localbase] [-l file] [-P type] [-Q quick-destdir] pkg-name [...]'); -our ($opt_a, $opt_v, $opt_n, $opt_I, $opt_L, $opt_B, $opt_A, $opt_P, $opt_Q, $opt_x, $opt_r, $opt_q, $opt_c, $opt_i, $opt_u, $opt_l, $opt_z); -$opt_v = 0; -try { - getopts('aqchivnruxzIl:L:f:F:B:A:P:Q:', - { - 'h' => sub { Usage(); }, - 'F' => sub { - for my $o (split /\,/o, shift) { - $defines{$o} = 1; - } - }, - 'f' => sub { - for my $o (split /\,/o, shift) { - $defines{$o} = 1; - } - }}); -} catchall { - Usage($_); -}; +$state = OpenBSD::pkg_add::State->new; -try { -$opt_L = OpenBSD::Paths->localbase unless defined $opt_L; +our ($opt_a, $opt_A, $opt_P, $opt_Q, $opt_r, $opt_u, $opt_l, $opt_z); -my $state = OpenBSD::pkg_add::State->new; +handle_options('aqchruzl:A:P:Q:'); + +try { $state->{cache} = {}; -$state->{recorder} = OpenBSD::SharedItemsRecorder->new; $state->{do_faked} = 0; -$state->{localbase} = $opt_L; $state->{arch} = $opt_A; -$state->{defines} = \%defines; if (defined $opt_Q and defined $opt_B) { Usage "-Q and -B are incompatible options"; @@ -656,17 +633,7 @@ if (defined $state->{destdir}) { } -$state->{not} = $opt_n; -# XXX RequiredBy -$not = $opt_n; -$state->{quick} = $opt_q; -$state->{extra} = $opt_c; $state->{automatic} = $opt_a; -$state->{dont_run_scripts} = $opt_I; -$state->{very_verbose} = $opt_v >= 2; -$state->{verbose} = $opt_v; -$state->{interactive} = $opt_i; -$state->{beverbose} = $opt_n || ($opt_v >= 2); $state->{allow_replacing} = $opt_r || $opt_u; if (@ARGV == 0 && !$opt_u && !$opt_l) { @@ -678,9 +645,7 @@ if ($opt_l && @ARGV != 0) { } -lock_db($state->{not}) unless $state->{defines}->{nolock}; -$state->setup_progressmeter($opt_x); -$state->check_root; +setup_state(); # Here we create the list of packages to install # actually, an updateset list (@todo2), and we hope to do this lazily @@ -777,38 +742,17 @@ if ($opt_l || $opt_z) { OpenBSD::Add::tag_user_packages(@todo2); } -if ($bad) { - exit(1); -} - - -my $handler = sub { my $sig = shift; die "Caught SIG$sig"; }; -local $SIG{'INT'} = $handler; -local $SIG{'QUIT'} = $handler; -local $SIG{'HUP'} = $handler; -local $SIG{'KILL'} = $handler; -local $SIG{'TERM'} = $handler; -my $code = sub { +my $dielater = do_the_main_work( +sub { # This is the actual very small loop that adds all packages $state->tracker->add_sets(@todo2); while (my $set = shift @todo2) { unshift(@todo2, install_set($set, $state)); } -}; - -if ($state->{defines}->{debug}) { - &$code; -} else { - eval { &$code; }; -} -my $dielater = $@; +}); -# cleanup various things -$state->{recorder}->cleanup($state); -OpenBSD::PackingElement::Fontdir::finish_fontdirs($state); OpenBSD::Add::manpages_index($state); -OpenBSD::PackingElement::Lib::ensure_ldconfig($state); # and display delayed thingies. @@ -819,11 +763,6 @@ if ($state->{packages_with_sig}) { } print "\n"; } -if ($state->{beverbose}) { - OpenBSD::Vstat::tally(); -} -$state->progress->clear; -$state->log->dump; if (defined $state->{updatedepends} && %{$state->{updatedepends}}) { print "Forced updates, bogus dependencies for ", join(' ', sort(keys %{$state->{updatedepends}})), diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index 762fcf6cdc6..b82d7324dd5 100644 --- a/usr.sbin/pkg_add/pkg_delete +++ b/usr.sbin/pkg_add/pkg_delete @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_delete,v 1.120 2009/11/14 10:47:17 espie Exp $ +# $OpenBSD: pkg_delete,v 1.121 2009/11/16 12:20:32 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -19,51 +19,28 @@ use strict; use warnings; -use OpenBSD::Getopt; +use OpenBSD::AddDelete; + +package OpenBSD::pkg_delete::State; +our @ISA=(qw(OpenBSD::UI)); + +package OpenBSD::AddDelete; +our ($state, %defines, $bad, $opt_B); + use OpenBSD::PackingList; use OpenBSD::RequiredBy; -use OpenBSD::Error; use OpenBSD::Interactive; use OpenBSD::Delete; use OpenBSD::PackageInfo; use OpenBSD::Vstat; -use OpenBSD::Paths; use OpenBSD::UpdateSet; -our %defines = (); -our $not; - -package OpenBSD::pkg_delete::State; -our @ISA=(qw(OpenBSD::pkg_foo::State)); - -package main; - set_usage('pkg_delete [-cIinqvx] [-B pkg-destdir] [-F keywords] pkg-name [...]'); -our ($opt_v, $opt_D, $opt_d, $opt_n, $opt_q, $opt_p, $opt_c, $opt_L, $opt_B, $opt_I, $opt_i, $opt_x); - -$opt_v = 0; - -try { - getopts('vchixDdnf:F:qpS:L:B:I', - { - 'h' => sub { Usage(); }, - 'F' => sub { - for my $o (split /\,/o, shift) { - $defines{$o} = 1; - } - }, - 'f' => sub { - for my $o (split /\,/o, shift) { - $defines{$o} = 1; - } - }}); -} catchall { - Usage($_); -}; +$state = OpenBSD::pkg_delete::State->new; +our ($opt_d, $opt_p, $opt_i); + +handle_options('chixDdnqpS:'); -if ($opt_D) { - $opt_I = 1; -} $opt_B = $ENV{'PKG_DESTDIR'} unless defined $opt_B; $opt_B = '' unless defined $opt_B; if ($opt_B ne '') { @@ -71,8 +48,6 @@ if ($opt_B ne '') { } $ENV{'PKG_DESTDIR'} = $opt_B; -$opt_L = OpenBSD::Paths->localbase unless defined $opt_L; - if (defined $opt_p) { Usage "Option p is obsolete"; } @@ -83,21 +58,7 @@ if (defined $opt_d) { my %done; my $removed; -try { -my $state = OpenBSD::pkg_delete::State->new; -$state->{recorder} = OpenBSD::SharedItemsRecorder->new; -$state->{not} = $opt_n; -# XXX RequiredBy -$not = $opt_n; -$state->{quick} = $opt_q; -$state->{very_verbose} = $opt_v >=2; -$state->{verbose} = $opt_v; -$state->{beverbose} = $opt_n || ($opt_v >= 2); -$state->{extra} = $opt_c; -$state->{dont_run_scripts} = $opt_I; -$state->{defines} = \%defines; $state->{destdir} = $opt_B; -$state->{interactive} = $opt_i; if ($opt_B eq '') { $state->{destdirname} = ''; } else { @@ -106,14 +67,12 @@ if ($opt_B eq '') { $ENV{'PKG_DELETE_EXTRA'} = $state->{extra} ? "Yes" : "No"; -lock_db($opt_n) unless $state->{defines}->{nolock}; -$state->setup_progressmeter($opt_x); -$state->check_root; +try { +setup_state(); # First, resolve pkg names my @realnames; -my $bad; OpenBSD::PackageInfo::solve_installed_names(\@ARGV, \@realnames, "(removing them all)", $state); @@ -157,18 +116,8 @@ if (@todo > @realnames) { } } -if ($bad) { - exit(1); -} - -my $handler = sub { my $sig = shift; die "Caught SIG$sig"; }; -local $SIG{'INT'} = $handler; -local $SIG{'QUIT'} = $handler; -local $SIG{'HUP'} = $handler; -local $SIG{'KILL'} = $handler; -local $SIG{'TERM'} = $handler; - -my $code = sub { +my $dielater = do_the_main_work( +sub { # and finally, handle the removal do { $removed = 0; @@ -195,7 +144,7 @@ my $code = sub { } } if (!$state->progress->set_header($pkgname)) { - print $opt_n ? "Pretending to delete " : + print $state->{not} ? "Pretending to delete " : "Deleting ", "$pkgname\n"; } @@ -205,23 +154,8 @@ my $code = sub { $removed++; } } while ($removed); -}; -if ($state->{defines}->{debug}) { - &$code; -} else { - eval { &$code; }; -} -my $dielater = $@; +}); -$state->{recorder}->cleanup($state); -OpenBSD::PackingElement::Lib::ensure_ldconfig($state); -OpenBSD::PackingElement::Fontdir::finish_fontdirs($state); - -if ($state->{beverbose}) { - OpenBSD::Vstat::tally(); -} -$state->progress->clear; -$state->log->dump; rethrow $dielater; } catch { print STDERR "$0: $_\n"; |