summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-05-13 11:14:26 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-05-13 11:14:26 +0000
commit81b933d1cc92f241e683e0507889275004cc99ef (patch)
treef138eba0be92390e57f57f02855808844175fc3e
parent3525c1467826f6c24f17fe6b765055742282989b (diff)
move most of the code into one process_package method
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm196
1 files changed, 101 insertions, 95 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index a2593a29c2e..ff02ad53627 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.70 2007/05/13 10:43:33 espie Exp $
+# $OpenBSD: Update.pm,v 1.71 2007/05/13 11:14:25 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -55,6 +55,105 @@ sub add2updates
push(@{$self->{updates}}, @args);
}
+sub process_package
+{
+ my ($self, $pkgname, $state) = @_;
+ if ($pkgname =~ m/^(?:\.libs|partial)\-/) {
+ OpenBSD::ProgressMeter::clear();
+ print "Not updating $pkgname, remember to clean it\n";
+ next;
+ }
+ my $stem = OpenBSD::PackageName::splitstem($pkgname);
+ my @l = OpenBSD::PackageLocator->findstem($stem);
+ if (@l == 0) {
+ $self->add2cant($pkgname);
+ return;
+ }
+ my @l2 = ();
+ if (@l > 1 && !$state->{forced}->{allversions}) {
+ @l = OpenBSD::PackageName::keep_most_recent(@l);
+ }
+ if (@l == 1 && $state->{forced}->{pkgpath}) {
+ OpenBSD::ProgressMeter::clear();
+ print "Directly updating $pkgname -> ", $l[0], "\n";
+ $self->add2updates($l[0]);
+ return;
+ }
+ my $plist = OpenBSD::PackingList->from_installation($pkgname, \&OpenBSD::PackingList::UpdateInfoOnly);
+ if (!defined $plist) {
+ Fatal("Can't locate $pkgname");
+ }
+ my $found;
+ for my $candidate (@l) {
+ my $handle = OpenBSD::PackageLocator->find($candidate, $state->{arch});
+ if (!$handle) {
+ next;
+ }
+ $handle->close_now;
+ my $p2 = $handle->plist(\&OpenBSD::PackingList::UpdateInfoOnly);
+ if (!$p2) {
+ next;
+ }
+ if ($p2->has('arch')) {
+ unless ($p2->{arch}->check($state->{arch})) {
+ next;
+ }
+ }
+ if ($plist->signature() eq $p2->signature()) {
+ $found = $candidate;
+ }
+ if ($p2->{extrainfo}->{subdir} eq $plist->{extrainfo}->{subdir}) {
+ push(@l2, $candidate);
+ } elsif ($p2->has('pkgpath')) {
+ for my $p (@{$p2->{pkgpath}}) {
+ if ($p->{name} eq $plist->{extrainfo}->{subdir}) {
+ push(@l2, $candidate);
+ last;
+ }
+ }
+ }
+ }
+
+ if (defined $found && @l2 == 1 && $found eq $l2[0]) {
+ if (!$plist->uses_old_libs) {
+ my $msg = "No need to update $pkgname";
+ OpenBSD::ProgressMeter::message($msg);
+ print "$msg\n" if $state->{beverbose};
+ return;
+ }
+ }
+ OpenBSD::ProgressMeter::clear();
+ print "Candidates for updating $pkgname -> ", join(' ', @l2), "\n";
+ # if all packages have the same version, but distinct p,
+ # grab the most recent.
+ if (@l2 > 1) {
+ @l2 = OpenBSD::PackageName::keep_most_recent(@l2);
+ }
+
+ if (@l2 == 1) {
+ if (defined $found && $found eq $l2[0] && !$plist->uses_old_libs) {
+ my $msg = "No need to update $pkgname";
+ OpenBSD::ProgressMeter::message($msg);
+ print "$msg\n" if $state->{beverbose};
+ } else {
+ $self->add2updates($l2[0]);
+ }
+ } elsif (@l2 == 0) {
+ $self->add2cant($pkgname);
+ } else {
+ my $result = OpenBSD::Interactive::choose1($pkgname, $state->{interactive}, sort @l2);
+ if (defined $result) {
+ if (defined $found && $found eq $result && !$plist->uses_old_libs) {
+ print "No need to update $pkgname\n";
+ } else {
+ $self->add2updates($result);
+ }
+ } else {
+ $state->{issues} = 1;
+ }
+ }
+}
+
sub process
{
my ($self, $old, $state) = @_;
@@ -69,100 +168,7 @@ sub process
OpenBSD::ProgressMeter::set_header("Looking for updates");
for my $pkgname (@list) {
- if ($pkgname =~ m/^(?:\.libs|partial)\-/) {
- OpenBSD::ProgressMeter::clear();
- print "Not updating $pkgname, remember to clean it\n";
- next;
- }
- my $stem = OpenBSD::PackageName::splitstem($pkgname);
- my @l = OpenBSD::PackageLocator->findstem($stem);
- if (@l == 0) {
- $self->add2cant($pkgname);
- next;
- }
- my @l2 = ();
- if (@l > 1 && !$state->{forced}->{allversions}) {
- @l = OpenBSD::PackageName::keep_most_recent(@l);
- }
- if (@l == 1 && $state->{forced}->{pkgpath}) {
- OpenBSD::ProgressMeter::clear();
- print "Directly updating $pkgname -> ", $l[0], "\n";
- $self->add2updates($l[0]);
- next;
- }
- my $plist = OpenBSD::PackingList->from_installation($pkgname, \&OpenBSD::PackingList::UpdateInfoOnly);
- if (!defined $plist) {
- Fatal("Can't locate $pkgname");
- }
- my $found;
- for my $candidate (@l) {
- my $handle = OpenBSD::PackageLocator->find($candidate, $state->{arch});
- if (!$handle) {
- next;
- }
- $handle->close_now;
- my $p2 = $handle->plist(\&OpenBSD::PackingList::UpdateInfoOnly);
- if (!$p2) {
- next;
- }
- if ($p2->has('arch')) {
- unless ($p2->{arch}->check($state->{arch})) {
- next;
- }
- }
- if ($plist->signature() eq $p2->signature()) {
- $found = $candidate;
- }
- if ($p2->{extrainfo}->{subdir} eq $plist->{extrainfo}->{subdir}) {
- push(@l2, $candidate);
- } elsif ($p2->has('pkgpath')) {
- for my $p (@{$p2->{pkgpath}}) {
- if ($p->{name} eq $plist->{extrainfo}->{subdir}) {
- push(@l2, $candidate);
- last;
- }
- }
- }
- }
-
- if (defined $found && @l2 == 1 && $found eq $l2[0]) {
- if (!$plist->uses_old_libs) {
- my $msg = "No need to update $pkgname";
- OpenBSD::ProgressMeter::message($msg);
- print "$msg\n" if $state->{beverbose};
- next;
- }
- }
- OpenBSD::ProgressMeter::clear();
- print "Candidates for updating $pkgname -> ", join(' ', @l2), "\n";
- # if all packages have the same version, but distinct p,
- # grab the most recent.
- if (@l2 > 1) {
- @l2 = OpenBSD::PackageName::keep_most_recent(@l2);
- }
-
- if (@l2 == 1) {
- if (defined $found && $found eq $l2[0] && !$plist->uses_old_libs) {
- my $msg = "No need to update $pkgname";
- OpenBSD::ProgressMeter::message($msg);
- print "$msg\n" if $state->{beverbose};
- } else {
- $self->add2updates($l2[0]);
- }
- } elsif (@l2 == 0) {
- $self->add2cant($pkgname);
- } else {
- my $result = OpenBSD::Interactive::choose1($pkgname, $state->{interactive}, sort @l2);
- if (defined $result) {
- if (defined $found && $found eq $result && !$plist->uses_old_libs) {
- print "No need to update $pkgname\n";
- } else {
- $self->add2updates($result);
- }
- } else {
- $state->{issues} = 1;
- }
- }
+ $self->process_package($pkgname, $state);
}
OpenBSD::ProgressMeter::next();
}