diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-11-29 07:54:19 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-11-29 07:54:19 +0000 |
commit | 27d5f530118418e1ddd8a9e765b33105279f6ef5 (patch) | |
tree | 9a9903c6beacd1a321d4159475802fb7dc26b66b /usr.sbin/pkg_add | |
parent | 0ba21d3c14e00bce9b403948df1fbf54293f2d97 (diff) |
slightly simpler error handling
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 14 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 25 |
2 files changed, 24 insertions, 15 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index 7f1aac3fea7..93bb548bcd8 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.29 2009/11/28 16:46:20 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.30 2009/11/29 07:54:18 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -59,12 +59,18 @@ sub new return bless {newer => {}, older => {}, hints => []}, $class; } -sub set_error +sub cleanup { my ($self, $error) = @_; - for my $h ($self->older) { - $h->set_error($error); + for my $h ($self->older, $self->newer) { + $h->cleanup($error); } + $self->{error} //= $error; +} + +sub has_error +{ + &OpenBSD::Handle::has_error; } sub add_newer diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index aa0629bbe9e..b69a1e2264f 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.400 2009/11/29 06:51:12 espie Exp $ +# $OpenBSD: pkg_add,v 1.401 2009/11/29 07:54:18 espie Exp $ # # Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org> # @@ -165,9 +165,7 @@ sub complete $set->{installable} = $r; if (!$set->{installable}) { - for my $n ($set->newer) { - $n->cleanup(OpenBSD::Handle::CANT_INSTALL); - } + $set->cleanup(OpenBSD::Handle::CANT_INSTALL); } return 1; } @@ -213,7 +211,7 @@ sub can_install return 1 if @conflicts == 0; if (!$state->{allow_replacing}) { $state->say("Can't install ", $set->short_print, " because of conflicts (",join(',', @conflicts), ")"); - $set->set_error(OpenBSD::Handle::CANT_INSTALL); + $set->cleanup(OpenBSD::Handle::CANT_INSTALL); return; } @@ -225,7 +223,7 @@ sub can_install if (!OpenBSD::Replace::is_new_package_safe($plist, $state)) { $state->say("Can't safely update to ", $handle->pkgname," (use -F update to force it)"); - $handle->set_error(OpenBSD::Handle::CANT_INSTALL); + $set->cleanup(OpenBSD::Handle::CANT_INSTALL); return; } } @@ -234,7 +232,7 @@ sub can_install for my $toreplace (@conflicts) { if ($state->tracker->is_installed($toreplace)) { $state->errsay("Cannot replace $toreplace in ", $set->short_print, ": just got installed"); - $set->set_error(OpenBSD::Handle::CANT_INSTALL); + $set->cleanup(OpenBSD::Handle::CANT_INSTALL); return; } @@ -261,7 +259,7 @@ sub can_install if (!OpenBSD::Replace::can_old_package_be_replaced($old_handle->plist, $set, $state, \%conflicts)) { $state->say("Can't update $toreplace into ", $set->short_print); - $set->set_error(OpenBSD::Handle::CANT_INSTALL); + $set->cleanup(OpenBSD::Handle::CANT_INSTALL); return; } $set->add_older($old_handle) @@ -493,7 +491,7 @@ sub install_set for my $handle ($set->newer) { if ($state->tracker->is_installed($handle->pkgname)) { - $handle->cleanup(OpenBSD::Handle::ALREADY_INSTALLED); + $set->cleanup(OpenBSD::Handle::ALREADY_INSTALLED); return (); } } @@ -504,6 +502,7 @@ sub install_set for my $handle ($set->newer) { if ($handle->has_error(OpenBSD::Handle::ALREADY_INSTALLED)) { + $set->cleanup(OpenBSD::Handle::ALREADY_INSTALLED); return (); } if ($handle->has_error) { @@ -511,13 +510,17 @@ sub install_set $state->log("Can't install ", $handle->pkgname, ":", $handle->error_message, "\n"); $bad++; + $set->cleanup($handle->has_error); return (); } if ($handle->plist->has('arch')) { unless ($handle->plist->{arch}->check($state->{arch})) { - $state->say($handle->pkgname, " is not for the right architecture"); - return () unless $defines{arch}; + $state->log($handle->pkgname, " is not for the right architecture"); + if (!$defines{arch}) { + $set->cleanup(OpenBSD::Handle::CANT_INSTALL); + return (); + } } } } |