summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-11-08 11:18:42 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-11-08 11:18:42 +0000
commit64fb7208ebfacb8c8dfee6cb22778c3fc601e53f (patch)
tree0e61f66f8aa97224aa40ff8503ed90979f67ebc5 /usr.sbin
parent9a8b30600bf602bc541cacc6b1116f32ec60039c (diff)
tracker/updater methods for state that auto-create the object.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm12
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Handle.pm4
-rw-r--r--usr.sbin/pkg_add/pkg_add47
3 files changed, 38 insertions, 25 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index 3e3e8b58904..735eb957e86 100644
--- a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Dependencies.pm,v 1.78 2009/10/19 14:20:55 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.79 2009/11/08 11:18:41 espie Exp $
#
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
#
@@ -256,7 +256,7 @@ sub find_dep_in_stuff_to_install
{
my ($self, $state, $dep) = @_;
- return find_candidate($dep->spec, keys %{$state->{tracker}->{to_install}});
+ return find_candidate($dep->spec, keys %{$state->tracker->{to_install}});
}
sub solve_dependency
@@ -273,7 +273,7 @@ sub solve_dependency
}
$v = $self->find_dep_in_stuff_to_install($state, $dep);
if ($v) {
- push(@{$self->{deplist}}, $state->{tracker}->{to_install}->{$v});
+ push(@{$self->{deplist}}, $state->tracker->{to_install}->{$v});
return $v;
}
}
@@ -289,7 +289,7 @@ sub solve_dependency
if (!$state->{allow_replacing}) {
$v = $self->find_dep_in_stuff_to_install($state, $dep);
if ($v) {
- push(@{$self->{deplist}}, $state->{tracker}->{to_install}->{$v});
+ push(@{$self->{deplist}}, $state->tracker->{to_install}->{$v});
return $v;
}
}
@@ -298,7 +298,7 @@ sub solve_dependency
if ($v) {
my $s = OpenBSD::UpdateSet->from_location($v);
- $state->{tracker}->add_set($s);
+ $state->tracker->add_set($s);
push(@{$self->{deplist}}, $s);
return $v->{name};
@@ -307,7 +307,7 @@ sub solve_dependency
# resort to default if nothing else
$v = $dep->{def};
my $s = OpenBSD::UpdateSet->create_new($v);
- $state->{tracker}->add_set($s);
+ $state->tracker->add_set($s);
push(@{$self->{deplist}}, $s);
return $v;
}
diff --git a/usr.sbin/pkg_add/OpenBSD/Handle.pm b/usr.sbin/pkg_add/OpenBSD/Handle.pm
index 14f8e480c6c..54d4ea59fd0 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.6 2009/10/19 14:00:10 espie Exp $
+# $OpenBSD: Handle.pm,v 1.7 2009/11/08 11:18:41 espie Exp $
#
# Copyright (c) 2007-2009 Marc Espie <espie@openbsd.org>
#
@@ -177,7 +177,7 @@ sub get_plist
OpenBSD::Add::tweak_package_status($pkgname, $state);
print "Not reinstalling $pkgname\n" if $state->{verbose} and
!$handle->{tweaked};
- $state->{tracker}->{installed}->{$pkgname} = 1;
+ $state->tracker->{installed}->{$pkgname} = 1;
$location->close_now;
$location->wipe_info;
$handle->set_error(ALREADY_INSTALLED);
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 9d2a94f82f9..fa2db2e8016 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.371 2009/11/08 10:46:11 espie Exp $
+# $OpenBSD: pkg_add,v 1.372 2009/11/08 11:18:41 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -98,6 +98,26 @@ sub set_name_from_handle
$state->set_pkgname($h->pkgname);
}
+sub updater
+{
+ my $state = shift;
+ if (!defined $state->{updater}) {
+ require OpenBSD::Update;
+ $state->{updater} = OpenBSD::Update->new;
+ }
+ return $state->{updater};
+}
+
+sub tracker
+{
+ my $state = shift;
+ if (!defined $state->{tracker}) {
+ require OpenBSD::Tracker;
+ $state->{tracker} = OpenBSD::Tracker->new;
+ }
+ return $state->{tracker};
+}
+
package OpenBSD::UpdateSet;
use OpenBSD::PackageInfo;
use OpenBSD::Error;
@@ -208,7 +228,7 @@ sub can_install
}
for my $toreplace (@conflicts) {
- if ($state->{tracker}->is_installed($toreplace)) {
+ if ($state->tracker->is_installed($toreplace)) {
Warn "Cannot replace $toreplace with $pkgname: just got installed\n";
$handle->set_error(OpenBSD::Handle::CANT_INSTALL);
return;
@@ -443,7 +463,7 @@ sub install_set
}
for my $handle ($set->newer) {
- if ($state->{tracker}->is_installed($handle->pkgname)) {
+ if ($state->tracker->is_installed($handle->pkgname)) {
$handle->cleanup(OpenBSD::Handle::ALREADY_INSTALLED);
return ();
}
@@ -518,7 +538,7 @@ sub install_set
for my $handle ($set->newer) {
$handle->cleanup;
}
- $state->{tracker}->mark_installed($set);
+ $state->tracker->mark_installed($set);
return ();
}
@@ -662,9 +682,6 @@ $state->check_root;
# later for the most part...
my @todo2 = ();
-require OpenBSD::Tracker;
-$state->{tracker} = OpenBSD::Tracker->new;
-
if ($opt_l) {
open my $f, '<', $opt_l or die "$!: bad list $opt_l";
my $_;
@@ -678,26 +695,22 @@ if ($opt_l) {
# three cases:
# 1/ match fuzzily against a list
if ($opt_l || $opt_z) {
- require OpenBSD::Update;
- my $updater = OpenBSD::Update->new;
$state->progress->set_header("Looking for packages");
for my $_ (@ARGV) {
my $set = OpenBSD::UpdateSet->new->add_hints($_);
- if ($updater->process_hint($set, $_, $state)) {
+ if ($state->updater->process_hint($set, $_, $state)) {
push(@todo2, $set);
}
}
# 2/ update existing stuff
} elsif ($opt_u) {
- require OpenBSD::Update;
require OpenBSD::PackageRepository::Installed;
if (@ARGV == 0) {
@ARGV = sort(installed_packages());
$state->{full_update} = 1;
}
- my $updater = OpenBSD::Update->new;
my $inst = OpenBSD::PackageRepository::Installed->new;
$state->progress->set_header("Looking for updates");
for my $pkgname (@ARGV) {
@@ -714,21 +727,21 @@ if ($opt_l || $opt_z) {
my $set = OpenBSD::UpdateSet->new->add_older(OpenBSD::Handle->from_location($l));
my $problem = 0;
for my $l ($set->older) {
- (defined $updater->process_handle($set, $l, $state)) or $problem = 1;
+ (defined $state->updater->process_handle($set, $l, $state)) or $problem = 1;
}
if ($set->newer > 0) {
push(@todo2, $set);
} else {
- $state->{tracker}->mark_uptodate($set);
+ $state->tracker->mark_uptodate($set);
}
if ($problem) {
- $state->{tracker}->mark_cant_update($set);
+ $state->tracker->mark_cant_update($set);
}
}
}
$state->progress->next;
- my @cantupdate = $state->{tracker}->cant_update;
+ my @cantupdate = $state->tracker->cant_update;
if (@cantupdate > 0) {
print "Cannot find updates for ", join(', ', map {$_->short_print} (@cantupdate > 50 ? @cantupdate[1..50] : @cantupdate));
print " and more" if @cantupdate > 50;
@@ -772,7 +785,7 @@ local $SIG{'TERM'} = $handler;
# This is the actual very small loop that adds all packages
eval {
-$state->{tracker}->add_sets(@todo2);
+$state->tracker->add_sets(@todo2);
while (my $set = shift @todo2) {
unshift(@todo2, install_set($set, $state));
}