summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-11-29 11:22:26 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-11-29 11:22:26 +0000
commit81234400edda9522378801123bac38d504903222 (patch)
treefcc54bb918c555876570e5e3e0d2a8b178bedfcd /usr.sbin
parent4de884c57a9032f52c167129a0ccf37c027f713f (diff)
clean up conflict handling and dependency adjustement: build list
of conflict globally, add it as old handles, and then use it everywhere.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm58
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Replace.pm6
-rw-r--r--usr.sbin/pkg_add/pkg_add122
3 files changed, 112 insertions, 74 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index a2d1d0b480b..3f3ac16b702 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.86 2009/11/29 07:06:17 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.87 2009/11/29 11:22:25 espie Exp $
#
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
#
@@ -384,37 +384,45 @@ sub record_old_dependencies
}
}
-sub adjust_old_dependencies
+sub adjust_old_dependency_on
{
- my ($self, $state) = @_;
- for my $pkg ($self->{set}->newer) {
- my $pkgname = $pkg->pkgname;
- for my $o ($self->{set}->older) {
- next unless defined $o->{wantlist};
- require OpenBSD::Replace;
- require OpenBSD::RequiredBy;
-
- my $oldname = $o->pkgname;
-
- $state->say("Adjusting dependencies for ",
- "$pkgname/$oldname") if $state->{beverbose};
- my $d = OpenBSD::RequiredBy->new($pkgname);
- for my $dep (@{$o->{wantlist}}) {
- if (defined $self->{set}->{skipupdatedeps}->{$dep}) {
- $state->say("\tskipping $dep")
- if $state->{beverbose};
- next;
- }
- $state->say("\t$dep")
+ my ($self, $pkgname, $state) = @_;
+
+ my $set = $self->{set};
+
+ for my $o ($set->older) {
+ next unless defined $o->{wantlist};
+ require OpenBSD::Replace;
+ require OpenBSD::RequiredBy;
+
+ my $oldname = $o->pkgname;
+
+ $state->say("Adjusting dependencies for ",
+ "$pkgname/$oldname") if $state->{beverbose};
+ my $d = OpenBSD::RequiredBy->new($pkgname);
+ for my $dep (@{$o->{wantlist}}) {
+ if (defined $set->{older}->{$dep}) {
+ $state->say("\tskipping $dep")
if $state->{beverbose};
- $d->add($dep);
- OpenBSD::Replace::adjust_dependency($dep,
- $oldname, $pkgname);
+ next;
}
+ $state->say("\t$dep") if $state->{beverbose};
+ $d->add($dep);
+ OpenBSD::Replace::adjust_dependency($dep,
+ $oldname, $pkgname);
}
}
}
+sub adjust_old_dependencies
+{
+ my ($self, $state) = @_;
+
+ for my $pkg ($self->{set}->newer) {
+ $self->adjust_old_dependency_on($pkg->pkgname, $state);
+ }
+}
+
sub repair_dependencies
{
my ($self, $state) = @_;
diff --git a/usr.sbin/pkg_add/OpenBSD/Replace.pm b/usr.sbin/pkg_add/OpenBSD/Replace.pm
index e25b2f5b663..67a076cdc16 100644
--- a/usr.sbin/pkg_add/OpenBSD/Replace.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Replace.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Replace.pm,v 1.56 2009/11/29 06:51:12 espie Exp $
+# $OpenBSD: Replace.pm,v 1.57 2009/11/29 11:22:25 espie Exp $
#
# Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org>
#
@@ -308,7 +308,7 @@ sub perform_extraction
sub can_old_package_be_replaced
{
- my ($old_plist, $set, $state, $ignore) = @_;
+ my ($old_plist, $set, $state) = @_;
$state->{okay} = 1;
$state->{journal} = [];
@@ -332,7 +332,7 @@ sub can_old_package_be_replaced
my @wantlist = OpenBSD::RequiredBy->new($old_plist->pkgname)->list;
my @r = ();
for my $wanting (@wantlist) {
- push(@r, $wanting) if !defined $ignore->{$wanting};
+ push(@r, $wanting) if !defined $set->{older}->{$wanting};
}
if (@r) {
$state->say("Verifying dependencies still match for ",
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index b69a1e2264f..590db4b069b 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.401 2009/11/29 07:54:18 espie Exp $
+# $OpenBSD: pkg_add,v 1.402 2009/11/29 11:22:25 espie Exp $
#
# Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org>
#
@@ -194,27 +194,25 @@ BIGLOOP: while (my ($pkg, $h) = each %todo) {
$set->{older} = \@l;
}
-sub can_install
+sub find_conflicts
{
my ($set, $state) = @_;
my @conflicts;
+
for my $handle ($set->newer) {
- my $plist = $handle->plist;
- push(@conflicts, OpenBSD::PkgCfl::find_all($plist, $state));
+ push(@conflicts,
+ OpenBSD::PkgCfl::find_all($handle->plist, $state));
}
-
-
my %conflicts = map {($_,1)} @conflicts;
- @conflicts = keys %conflicts;
+ return keys %conflicts;
+}
- return 1 if @conflicts == 0;
- if (!$state->{allow_replacing}) {
- $state->say("Can't install ", $set->short_print, " because of conflicts (",join(',', @conflicts), ")");
- $set->cleanup(OpenBSD::Handle::CANT_INSTALL);
- return;
- }
+sub is_new_stuff_safe
+{
+ my ($set, $state) = @_;
+ my $r = 1;
for my $handle ($set->newer) {
require OpenBSD::Replace;
@@ -223,61 +221,93 @@ sub can_install
if (!OpenBSD::Replace::is_new_package_safe($plist, $state)) {
$state->say("Can't safely update to ",
$handle->pkgname," (use -F update to force it)");
- $set->cleanup(OpenBSD::Handle::CANT_INSTALL);
- return;
+ $r = 0;
}
}
+ return $r;
+}
- my $manual_install = 0;
+sub mark_as_manual_install
+{
+ my $set = shift;
+
+ for my $handle ($set->newer) {
+ my $plist = $handle->plist;
+ $plist->has('manual-installation') or
+ OpenBSD::PackingElement::ManualInstallation->add($plist);
+ }
+}
+
+sub can_install
+{
+ my ($set, $state) = @_;
+
+ my @conflicts = $set->find_conflicts($state);
+
+ return 1 if @conflicts == 0;
+ if (!$state->{allow_replacing}) {
+ $state->say("Can't install ", $set->short_print,
+ " because of conflicts (",join(',', @conflicts), ")");
+ $set->cleanup(OpenBSD::Handle::CANT_INSTALL);
+ return;
+ }
+
+
+ if (!$set->is_new_stuff_safe($state)) {
+ $set->cleanup(OpenBSD::Handle::CANT_INSTALL);
+ return;
+ }
+
+ my $later = 0;
for my $toreplace (@conflicts) {
if ($state->tracker->is_installed($toreplace)) {
- $state->errsay("Cannot replace $toreplace in ", $set->short_print, ": just got installed");
+ $state->errsay("Cannot replace $toreplace in ",
+ $set->short_print, ": just got installed");
$set->cleanup(OpenBSD::Handle::CANT_INSTALL);
return;
}
- my $old_handle = $set->{older}->{$toreplace};
- if (defined $old_handle) {
- $old_handle->complete_old;
+ next if $set->{older}->{$toreplace};
+
+ $later = 1;
+ my $s = $state->tracker->is_to_update($toreplace);
+ if (defined $s) {
+ $set->merge($state->tracker, $s);
} else {
- my $s = $state->tracker->is_to_update($toreplace);
- if (defined $s) {
- $set->merge($state->tracker, $s);
- return 0;
- }
- $old_handle = OpenBSD::Handle->create_old($toreplace, $state);
- # XXX stuff to do
+ $set->add_older(OpenBSD::Handle->create_old($toreplace,
+ $state));
}
+ }
+
+ return 0 if $later;
+
+ my $manual_install = 0;
+
+ for my $old ($set->older) {
+ my $name = $old->pkgname;
+ $old->complete_old;
- if ($old_handle->has_error(OpenBSD::Handle::NOT_FOUND)) {
- Fatal "Can't find $toreplace as an installed package\n";
+ if ($old->has_error(OpenBSD::Handle::NOT_FOUND)) {
+ Fatal "Can't find $name as an installed package\n";
}
- if ($old_handle->has_error(OpenBSD::Handle::BAD_PACKAGE)) {
- Fatal "Couldn't find packing-list for $toreplace\n";
+ if ($old->has_error(OpenBSD::Handle::BAD_PACKAGE)) {
+ Fatal "Couldn't find packing-list for $name\n";
}
- if (!OpenBSD::Replace::can_old_package_be_replaced($old_handle->plist,
- $set, $state, \%conflicts)) {
- $state->say("Can't update $toreplace into ", $set->short_print);
+ if (!OpenBSD::Replace::can_old_package_be_replaced($old->plist,
+ $set, $state)) {
+ $state->say("Can't update $name into ",
+ $set->short_print);
$set->cleanup(OpenBSD::Handle::CANT_INSTALL);
return;
}
- $set->add_older($old_handle)
- if !defined $set->{older}->{$toreplace};
- if ($old_handle->plist->has('manual-installation')) {
+ if ($old->plist->has('manual-installation')) {
$manual_install = 1;
}
}
- if ($manual_install) {
- for my $handle ($set->newer) {
- my $plist = $handle->plist;
- if (!$plist->has('manual-installation')) {
- OpenBSD::PackingElement::ManualInstallation->add($plist);
- }
- }
- }
- $set->{skipupdatedeps} = \%conflicts;
+
+ $set->mark_as_manual_install if $manual_install;
return 1;
}