summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-10-19 14:00:11 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-10-19 14:00:11 +0000
commit5ee5e2e3fe83bf75469c502000e0990d8e369b8d (patch)
treea75934460632dc1863870fc57134cb60ee8349a6 /usr.sbin/pkg_add
parentb5c53523aecd80ed1bf1930079d1b8c4ca1b23ec (diff)
cleanup method that does more or less what's needed
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Handle.pm17
-rw-r--r--usr.sbin/pkg_add/pkg_add14
2 files changed, 20 insertions, 11 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Handle.pm b/usr.sbin/pkg_add/OpenBSD/Handle.pm
index 464698f035b..14f8e480c6c 100644
--- a/usr.sbin/pkg_add/OpenBSD/Handle.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Handle.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Handle.pm,v 1.5 2009/10/19 09:29:53 espie Exp $
+# $OpenBSD: Handle.pm,v 1.6 2009/10/19 14:00:10 espie Exp $
#
# Copyright (c) 2007-2009 Marc Espie <espie@openbsd.org>
#
@@ -29,6 +29,21 @@ use constant {
NOT_FOUND => 4
};
+sub cleanup
+{
+ my ($self, $error) = @_;
+ $self->{error} //= $error;
+ if (defined $self->location) {
+ if ($self->{error} == ALREADY_INSTALLED) {
+ $self->location->close_now;
+ } elsif ($self->{error} == CANT_INSTALL) {
+ $self->location->close_with_client_error;
+ }
+ $self->location->wipe_info;
+ }
+ delete $self->{plist};
+}
+
sub new
{
my $class = shift;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 4afa9f1844f..c57a7f16620 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.359 2009/10/19 09:29:53 espie Exp $
+# $OpenBSD: pkg_add,v 1.360 2009/10/19 14:00:10 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -153,10 +153,7 @@ sub complete
if (!$set->{installable}) {
for my $n ($set->newer) {
- $n->location->close_with_client_error;
- $n->location->wipe_info;
- delete $n->{plist};
- $n->set_error(OpenBSD::Handle::CANT_INSTALL);
+ $n->cleanup(OpenBSD::Handle::CANT_INSTALL);
}
}
}
@@ -454,9 +451,7 @@ sub install_set
my $handle = $set->handle;
if ($state->{tracker}->is_installed($handle->pkgname)) {
- if (defined $handle->location) {
- $handle->location->close_now;
- }
+ $handle->cleanup(OpenBSD::Handle::ALREADY_INSTALLED);
return ();
}
@@ -522,8 +517,7 @@ sub install_set
# }
# }
really_add($set, $state);
- $location->wipe_info;
- delete $handle->{plist};
+ $handle->cleanup;
$state->{tracker}->mark_installed($set);
return ();
}