summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-06-10 14:52:30 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-06-10 14:52:30 +0000
commit221436f0af147f7497bd167cb6a164fce6120588 (patch)
tree69f8d4205c2958df76e4db7bfa6bff2bde18f48a
parentb36c9f662da72870bf22394171cf74a54a7f8e39 (diff)
split create_handle code, so that we create the object as a trivial
place-holder, then complete it later. This should allow us to create `empty shell' UpdateSets eventually, in replacement of pkgnames lists.
-rw-r--r--usr.sbin/pkg_add/pkg_add154
1 files changed, 91 insertions, 63 deletions
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 19cba8a06c8..87d0927159f 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.316 2007/06/09 13:39:31 espie Exp $
+# $OpenBSD: pkg_add,v 1.317 2007/06/10 14:52:29 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -191,68 +191,7 @@ sub create_handle
my $handle = OpenBSD::Handle->new;
$handle->{pkgname} = $pkg;
$handle->{tweaked} = 0;
- my $location = OpenBSD::PackageLocator->find($pkg, $state->{arch});
- if (!$location) {
- print $state->deptree_header($pkg);
- $handle->set_error(OpenBSD::Handle::NOT_FOUND);
- $handle->{tweaked} =
- OpenBSD::Add::tweak_package_status($pkg, $state);
- if (!$handle->{tweaked}) {
- print "Can't find $pkg\n";
- }
- return $handle;
- }
- $handle->{location} = $location;
- if ($state->{verbose}) {
- print $state->deptree_header($pkg);
- print "parsing $pkg\n";
- }
- my $plist = $location->plist;
- unless (defined $plist) {
- print "Can't find CONTENTS from $pkg\n";
- $handle->set_error(OpenBSD::Handle::BAD_PACKAGE);
- $location->close_with_client_error;
- $location->wipe_info;
- return $handle;
- }
- $handle->{plist} = $plist;
- if ($plist->localbase ne $state->{localbase}) {
- print "Localbase mismatch: package has: ", $plist->localbase, " , user wants: ", $state->{localbase}, "\n";
- $location->close_with_client_error;
- $location->wipe_info;
- delete $handle->{plist};
- $handle->set_error(OpenBSD::Handle::BAD_PACKAGE);
- return $handle;
- }
- my $pkgname = $handle->{pkgname} = $plist->pkgname;
-
- if (is_installed($pkgname) &&
- (!$state->{allow_replacing} ||
- !$state->{forced}->{installed} &&
- !$plist->has_new_sig($state) &&
- !$plist->uses_old_libs)) {
- $handle->{tweaked} =
- OpenBSD::Add::tweak_package_status($pkgname, $state);
- print "Not reinstalling $pkgname\n" if $state->{verbose} and
- !$handle->{tweaked};
- $state->mark_as_already_installed($pkgname);
- $location->close_now;
- $location->wipe_info;
- delete $handle->{plist};
- $handle->set_error(OpenBSD::Handle::ALREADY_INSTALLED);
- return $handle;
- }
- if ($pkg ne '-') {
- if (!defined $pkgname or
- OpenBSD::PackageName::url2pkgname($pkg) ne $pkgname) {
- print "Package name is not consistent ???\n";
- $location->close_with_client_error;
- $location->wipe_info;
- delete $handle->{plist};
- $handle->set_error(OpenBSD::Handle::BAD_PACKAGE);
- return $handle;
- }
- }
+ $handle->complete($state);
return $handle;
}
@@ -774,3 +713,92 @@ sub has_new_sig
}
return $plist->{new_sig};
}
+
+package OpenBSD::Handle;
+use OpenBSD::PackageInfo;
+
+sub get_plist
+{
+ my ($handle, $state) = @_;
+
+ my $location = $handle->{location};
+ my $pkg = $handle->{pkgname};
+
+ if ($state->{verbose}) {
+ print $state->deptree_header($pkg);
+ print "parsing $pkg\n";
+ }
+ my $plist = $location->plist;
+ unless (defined $plist) {
+ print "Can't find CONTENTS from $pkg\n";
+ $location->close_with_client_error;
+ $location->wipe_info;
+ $handle->set_error(BAD_PACKAGE);
+ return;
+ }
+ if ($plist->localbase ne $state->{localbase}) {
+ print "Localbase mismatch: package has: ", $plist->localbase, " , user wants: ", $state->{localbase}, "\n";
+ $location->close_with_client_error;
+ $location->wipe_info;
+ $handle->set_error(BAD_PACKAGE);
+ return;
+ }
+ my $pkgname = $handle->{pkgname} = $plist->pkgname;
+
+ if (is_installed($pkgname) &&
+ (!$state->{allow_replacing} ||
+ !$state->{forced}->{installed} &&
+ !$plist->has_new_sig($state) &&
+ !$plist->uses_old_libs)) {
+ $handle->{tweaked} =
+ OpenBSD::Add::tweak_package_status($pkgname, $state);
+ print "Not reinstalling $pkgname\n" if $state->{verbose} and
+ !$handle->{tweaked};
+ $state->mark_as_already_installed($pkgname);
+ $location->close_now;
+ $location->wipe_info;
+ $handle->set_error(ALREADY_INSTALLED);
+ return;
+ }
+ if ($pkg ne '-') {
+ if (!defined $pkgname or
+ OpenBSD::PackageName::url2pkgname($pkg) ne $pkgname) {
+ print "Package name is not consistent ???\n";
+ $location->close_with_client_error;
+ $location->wipe_info;
+ $handle->set_error(BAD_PACKAGE);
+ return;
+ }
+ }
+ $handle->{plist} = $plist;
+}
+
+sub complete
+{
+ my ($handle, $state) = @_;
+
+ return if $handle->has_error;
+
+ my $pkgname = $handle->{pkgname};
+
+ if (!defined $handle->{location}) {
+ my $location = OpenBSD::PackageLocator->find($pkgname,
+ $state->{arch});
+ if (!$location) {
+ print $state->deptree_header($pkgname);
+ $handle->set_error(NOT_FOUND);
+ $handle->{tweaked} =
+ OpenBSD::Add::tweak_package_status($pkgname,
+ $state);
+ if (!$handle->{tweaked}) {
+ print "Can't find $pkgname\n";
+ }
+ return;
+ }
+ $handle->{location} = $location;
+ }
+ if (!defined $handle->{plist}) {
+ $handle->get_plist($state);
+ }
+
+}