diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-10-14 22:59:35 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-10-14 22:59:35 +0000 |
commit | b3a667760624e9fb4230a91fece174894f606d34 (patch) | |
tree | 9689fb2836e81b5e1bcf4ed783f769a07cf9a40c /usr.sbin | |
parent | bd565b860ae1095570a3f9d924ccc6f3c9d8614a (diff) |
move OpenBSD::Handle into its own file. I guess I need to disentangle this
code before I go further....
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Handle.pm | 183 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 80 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 90 |
4 files changed, 188 insertions, 168 deletions
diff --git a/usr.sbin/pkg_add/Makefile b/usr.sbin/pkg_add/Makefile index 8c75d5c79c0..ba6cf384294 100644 --- a/usr.sbin/pkg_add/Makefile +++ b/usr.sbin/pkg_add/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.52 2009/04/14 17:53:58 espie Exp $ +# $OpenBSD: Makefile,v 1.53 2009/10/14 22:59:34 espie Exp $ .include <bsd.own.mk> @@ -18,6 +18,7 @@ PACKAGES= \ OpenBSD/Dependencies.pm \ OpenBSD/Error.pm \ OpenBSD/Getopt.pm \ + OpenBSD/Handle.pm \ OpenBSD/IdCache.pm \ OpenBSD/Interactive.pm \ OpenBSD/Mtree.pm \ diff --git a/usr.sbin/pkg_add/OpenBSD/Handle.pm b/usr.sbin/pkg_add/OpenBSD/Handle.pm new file mode 100644 index 00000000000..15701fee4bd --- /dev/null +++ b/usr.sbin/pkg_add/OpenBSD/Handle.pm @@ -0,0 +1,183 @@ +# ex:ts=8 sw=4: +# $OpenBSD: Handle.pm,v 1.1 2009/10/14 22:59:34 espie Exp $ +# +# Copyright (c) 2007-2009 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +# fairly non-descriptive name. Used to store various package information +# during installs and updates. +package OpenBSD::Handle; + +use OpenBSD::PackageInfo; + +use constant { + BAD_PACKAGE => 1, + CANT_INSTALL => 2, + ALREADY_INSTALLED => 3, + NOT_FOUND => 4 +}; + +sub new +{ + my $class = shift; + return bless {}, $class; +} + +sub set_error +{ + my ($self, $error) = @_; + $self->{error} = $error; +} + +sub has_error +{ + my ($self, $error) = @_; + if (!defined $self->{error}) { + return undef; + } + if (defined $error) { + return $self->{error} eq $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; +} + +sub create_new +{ + my ($class, $pkg) = @_; + my $handle = $class->new; + $handle->{pkgname} = $pkg; + $handle->{tweaked} = 0; + return $handle; +} + +sub from_location +{ + my ($class, $location) = @_; + my $handle = $class->new; + $handle->{pkgname} = $location->name; + $handle->{location} = $location; + $handle->{tweaked} = 0; + return $handle; +} + +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->grabPlist; + unless (defined $plist) { + print "Can't find CONTENTS from ", $location->url, "\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->{defines}->{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_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); + } +} +1; diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index f17f5c18cb4..432eebe79ee 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.7 2009/10/14 10:38:06 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.8 2009/10/14 22:59:34 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -113,84 +113,6 @@ sub print print STDERR @_; } -# fairly non-descriptive name. Used to store various package information -# during installs and updates. -package OpenBSD::Handle; - -use constant { - BAD_PACKAGE => 1, - CANT_INSTALL => 2, - ALREADY_INSTALLED => 3, - NOT_FOUND => 4 -}; - -sub new -{ - my $class = shift; - return bless {}, $class; -} - -sub set_error -{ - my ($self, $error) = @_; - $self->{error} = $error; -} - -sub has_error -{ - my ($self, $error) = @_; - if (!defined $self->{error}) { - return undef; - } - if (defined $error) { - return $self->{error} eq $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; -} - -sub create_new -{ - my ($class, $pkg) = @_; - my $handle = $class->new; - $handle->{pkgname} = $pkg; - $handle->{tweaked} = 0; - return $handle; -} - -sub from_location -{ - my ($class, $location) = @_; - my $handle = $class->new; - $handle->{pkgname} = $location->name; - $handle->{location} = $location; - $handle->{tweaked} = 0; - return $handle; -} - package OpenBSD::UpdateSet; sub new { diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 07153a6ae35..8c5be5f4c69 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.351 2009/10/14 18:22:41 espie Exp $ +# $OpenBSD: pkg_add,v 1.352 2009/10/14 22:59:34 espie Exp $ # # Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org> # @@ -34,6 +34,7 @@ use OpenBSD::Add; use OpenBSD::SharedLibs; use OpenBSD::Paths; use OpenBSD::UpdateSet; +use OpenBSD::Handle; my $bad = 0; @@ -64,93 +65,6 @@ 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->grabPlist; - unless (defined $plist) { - print "Can't find CONTENTS from ", $location->url, "\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->{defines}->{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_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); - } -} package OpenBSD::pkg_add::State; our @ISA=(qw(OpenBSD::pkg_foo::State)); |