summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-06-10 16:05:50 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-06-10 16:05:50 +0000
commitd4c7bc29b9e295e2a35a6b4aa36526d4f5028ba2 (patch)
tree6d5e7fcfcd438c78b84421b81baf337b9a447ea3 /usr.sbin/pkg_add
parent86916761cdd1d1dcac8c97af812a86b5033e70f6 (diff)
extract constructor to create old handles.
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Vstat.pm25
-rw-r--r--usr.sbin/pkg_add/pkg_add20
2 files changed, 32 insertions, 13 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Vstat.pm b/usr.sbin/pkg_add/OpenBSD/Vstat.pm
index e89a781f071..a951f971b6d 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.38 2007/06/07 12:57:33 espie Exp $
+# $OpenBSD: Vstat.pm,v 1.39 2007/06/10 16:05:49 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -346,6 +346,29 @@ sub has_error
return $self->{error};
}
+sub create_old
+{
+
+ my ($class, $pkgname, $state) = @_;
+ my $self= $class->new;
+ $self->{pkgname} = $pkgname;
+
+ require OpenBSD::PackageRepository::Installed;
+
+ my $location = OpenBSD::PackageRepository::Installed->new->find($pkgname, $state->{arch});
+ if (!defined $location) {
+ $self->set_error(NOT_FOUND);
+ } else {
+ $self->{location} = $location;
+ my $plist = $location->plist;
+ if (!defined $plist) {
+ $self->set_error(BAD_PACKAGE);
+ } else {
+ $self->{plist} = $plist;
+ }
+ }
+ return $self;
+}
package OpenBSD::UpdateSet;
sub new
{
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index d165c1211d9..de8828f7f04 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.319 2007/06/10 15:24:36 espie Exp $
+# $OpenBSD: pkg_add,v 1.320 2007/06/10 16:05:49 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -165,27 +165,23 @@ sub can_install
return;
}
- my $old_handle = OpenBSD::Handle->new;
- $old_handle->{pkgname} = $toreplace;
- $old_handle->{location} = OpenBSD::PackageRepository::Installed->new->find($toreplace, $state->{arch});
- if (!$old_handle->{location}) {
+ my $old_handle = OpenBSD::Handle->create_old($toreplace, $state);
+ if ($old_handle->has_error(OpenBSD::Handle::NOT_FOUND)) {
Fatal "Can't find $toreplace as an installed package\n";
}
- my $rplist = $old_handle->{location}->plist;
- if (!defined $rplist) {
+ if ($old_handle->has_error(OpenBSD::Handle::BAD_PACKAGE)) {
Fatal "Couldn't find packing-list for $toreplace\n";
}
- $old_handle->{plist} = $rplist;
- if (!OpenBSD::Replace::can_old_package_be_replaced($rplist,
+ if (!OpenBSD::Replace::can_old_package_be_replaced($old_handle->{plist},
$pkgname, $state, \%conflicts)) {
print "Can't update $toreplace into $pkgname\n";
$handle->set_error(OpenBSD::Handle::CANT_INSTALL);
return;
}
-
$set->add_older($old_handle);
- if ($rplist->has('manual-installation') &&
+
+ if ($old_handle->{plist}->has('manual-installation') &&
!$plist->has('manual-installation')) {
OpenBSD::PackingElement::ManualInstallation->add($plist);
}
@@ -809,5 +805,5 @@ sub complete
if (!defined $handle->{plist}) {
$handle->get_plist($state);
}
-
}
+