summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-10-13 21:21:08 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-10-13 21:21:08 +0000
commit1bccb82fe0080928ffe5581cfd05ab1c6dc9a452 (patch)
tree418865eada3e1a95c7c2e79747f4a8bfe7259f44 /usr.sbin/pkg_add
parent37c48ece580d4aeacd2f905999d656ff184ffb9c (diff)
deal with UpdateSets earlier: build an updateset, and ask Update to complete
it. Tweak the control for updates to move to main program. Eventually, we will run updates on the fly (there's still some merging code and debugging to go)
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm83
-rw-r--r--usr.sbin/pkg_add/pkg_add74
2 files changed, 69 insertions, 88 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index f35e5a72252..5ff19f64c7e 100644
--- a/usr.sbin/pkg_add/OpenBSD/Update.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Update.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Update.pm,v 1.84 2009/06/06 11:48:04 espie Exp $
+# $OpenBSD: Update.pm,v 1.85 2009/10/13 21:21:07 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -23,44 +23,36 @@ use OpenBSD::PackageInfo;
use OpenBSD::PackageLocator;
use OpenBSD::PackageName;
use OpenBSD::Error;
+use OpenBSD::UpdateSet;
sub new
{
my $class = shift;
- return bless {cant => [], updates => []}, $class;
+ return bless {}, $class;
}
-sub cant
+sub add_updateset
{
- my $self = shift;
- return $self->{cant};
+ my ($self, $set, $handle, $location) = @_;
+
+ my $n = OpenBSD::Handle->from_location($location);
+ $set->add_newer($n);
}
-sub updates
+sub process_handle
{
- my $self = shift;
- return $self->{updates};
-}
-
-sub add2cant
-{
- my ($self, @args) = @_;
- push(@{$self->{cant}}, @args);
-}
-
-sub add2updates
-{
- my ($self, @args) = @_;
- push(@{$self->{updates}}, @args);
-}
-
-sub process_package
-{
- my ($self, $pkgname, $state) = @_;
+ my ($self, $set, $h, $state) = @_;
+ my $pkgname = $h->{pkgname};
+ if (defined $h->{update}) {
+ $state->progress->clear;
+ print "Update to $pkgname already found\n";
+ return 0;
+ }
+
if ($pkgname =~ m/^(?:\.libs\d*|partial)\-/o) {
$state->progress->clear;
print "Not updating $pkgname, remember to clean it\n";
- return;
+ return 0;
}
my @search = ();
push(@search, OpenBSD::Search::Stem->split($pkgname));
@@ -114,22 +106,21 @@ sub process_package
my $l = OpenBSD::PackageLocator->match_locations(@search);
if (@$l == 0) {
- $self->add2cant($pkgname);
- return;
+ return undef;
}
if (@$l == 1) {
if ($state->{defines}->{pkgpath}) {
$state->progress->clear;
print "Directly updating $pkgname -> ", $l->[0]->name, "\n";
- $self->add2updates($l->[0]);
- return;
+ $self->add_updateset($set, $h, $l->[0]);
+ return 1;
}
- if (defined $found && $found eq $l->[0] &&
+ if (defined $found && $found eq $l->[0] &&
!$plist->uses_old_libs && !$state->{defines}->{installed}) {
my $msg = "No need to update $pkgname";
$state->progress->message($msg);
print "$msg\n" if $state->{beverbose};
- return;
+ return 0;
}
}
@@ -138,8 +129,8 @@ sub process_package
print "Candidates for updating $pkgname -> ", join(' ', keys %cnd), "\n";
if (@$l == 1) {
- $self->add2updates($l->[0]);
- return;
+ $self->add_updateset($set, $h, $l->[0]);
+ return 1;
}
my $result = OpenBSD::Interactive::choose1($pkgname,
$state->{interactive}, sort keys %cnd);
@@ -147,31 +138,15 @@ sub process_package
if (defined $found && $found eq $result &&
!$plist->uses_old_libs) {
print "No need to update $pkgname\n";
+ return 0;
} else {
- $self->add2updates($cnd{$result});
+ $self->add_updateset($set, $h, $cnd{$result});
+ return 1;
}
} else {
$state->{issues} = 1;
+ return undef;
}
}
-sub process
-{
- my ($self, $old, $state) = @_;
- my @list = ();
-
- OpenBSD::PackageInfo::solve_installed_names($old, \@list, "(updating them all)", $state);
- unless (defined $state->{full_update} or defined $state->{defines}->{noclosure}) {
- require OpenBSD::RequiredBy;
-
- @list = OpenBSD::Requiring->compute_closure(@list);
- }
-
- $state->progress->set_header("Looking for updates");
- for my $pkgname (@list) {
- $self->process_package($pkgname, $state);
- }
- $state->progress->next;
-}
-
1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index d2da4b78390..3ab2790a764 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.344 2009/10/13 12:57:14 espie Exp $
+# $OpenBSD: pkg_add,v 1.345 2009/10/13 21:21:07 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -674,19 +674,6 @@ sub find_truelocations
}
}
-sub reorder
-{
- my $l = shift;
- my $n = @$l;
- my ($a, $i, $j);
- for ($i = 0; $i < $n; $i++) {
- $j = int(rand($n-$i));
- $a = $l->[$i];
- $l->[$i] = $l->[$n-$j-1];
- $l->[$n-$j-1] = $a;
- }
-}
-
set_usage('pkg_add [-acIinqruvxz] [-A arch] [-B pkg-destdir] [-F keywords]',
'[-L localbase] [-l file] [-P type] [-Q quick-destdir] pkg-name [...]');
@@ -801,25 +788,23 @@ if ($opt_l || $opt_z) {
my $l;
# first try to find us exactly
$state->progress->message("Looking for $_");
- $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Exact->new($_));
+ $l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Exact->new($_), $k);
if (@$l == 0) {
- my @search =();
my $t = $_;
$t =~ s/\-\d([^-]*)\-?/--/;
- push(@search, OpenBSD::Search::Stem->new($t));
$l = OpenBSD::PackageLocator->match_locations(OpenBSD::Search::Stem->new($t), $k);
}
if (@$l == 0) {
$state->progress->clear;
print "Can't find $_\n";
} elsif (@$l > 1) {
+ $state->progress->clear;
if ($state->{interactive}) {
my %cnd = map {($_->name, $_)} @$l;
my $result = OpenBSD::Interactive::choose1($_,
1, sort keys %cnd);
push @todo, $cnd{$result} if defined $result;
} else {
- $state->progress->clear;
print "Ambiguous: $_\n";
}
} else {
@@ -829,17 +814,50 @@ if ($opt_l || $opt_z) {
}
} 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;
- $updater->process(\@ARGV, $state);
- my @cantupdate = @{$updater->cant};
+ my $inst = OpenBSD::PackageRepository::Installed->new;
+ $state->progress->set_header("Looking for updates");
+ my @cantupdate = ();
+ for my $pkgname (@ARGV) {
+ my $l;
+
+ if (OpenBSD::PackageName::is_stem($pkgname)) {
+ $l = stem2location($inst, $pkgname, $state);
+ } else {
+ $l = $inst->find($pkgname, $state->{arch});
+ }
+ if (!defined $l) {
+ print "Problem finding $pkgname\n";
+ } else {
+ 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;
+ }
+ if ($set->newer > 0) {
+ push(@todo2, $set);
+ }
+ if ($problem) {
+ push(@cantupdate, $set);
+ }
+ }
+ }
+ $state->progress->next;
if (@cantupdate > 0) {
- print "Cannot find updates for ", join(' ', @cantupdate), "\n";
+ print "Cannot find updates for ", join(', ', map {$_->short_print} @cantupdate[1..50]);
+ print " and more" if @cantupdate > 50;
+ print "\n";
+ if (@todo == 0) {
+ print "No updates found\n";
+ exit(1);
+ }
if ($state->{defines}->{alwaysupdate} ||
$state->{full_update} && !$state->{interactive}) {
print "Proceeding anyways\n";
@@ -854,22 +872,10 @@ if ($opt_l || $opt_z) {
print "There are some ambiguities. Please run in interactive ".
"mode again.\n";
}
- @todo = @{$updater->updates};
- if (@todo > 0 && !$bad) {
- print "Running the equivalent of pkg_add -r ",
- join(' ', (map {$_->name} @todo)), "\n";
- }
- @todo2 = map { OpenBSD::UpdateSet->from_location($_) } @todo;
+ print "Running update ", join(',', map {$_->short_print} @todo2), "\n";
} else {
find_truelocations(\@ARGV, \@todo2, $state);
OpenBSD::Add::tag_user_packages(@todo2);
-# if (defined $state->{defines}->{kitchensink}) {
-# reorder(\@todo);
-# if (!$opt_r) {
-# @todo = grep {s/\.tgz$//o; !is_installed($_);} @todo;
-# }
-# print "Adding in order:\n", (map { "\t$_\n" } @todo), "\n";
-# }
}
if ($bad) {