summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2009-12-27 22:26:29 +0000
committerMarc Espie <espie@cvs.openbsd.org>2009-12-27 22:26:29 +0000
commitaee9fb9eedb4e3ca49869b5efa4714ba66713dd0 (patch)
tree8f96b4c722d8949aaa8b638065143eacb24818c9
parent9161b8526f0eb815903c6773bc5403b1bd2650c7 (diff)
check for loops and merge sets, in case we end up with real funky depends.
also, reset package->{before} before solving depends, since we may solve them several times.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Dependencies.pm33
1 files changed, 32 insertions, 1 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Dependencies.pm b/usr.sbin/pkg_add/OpenBSD/Dependencies.pm
index d21f2cb2c8b..4aac0a5abcb 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.100 2009/12/26 21:14:57 espie Exp $
+# $OpenBSD: Dependencies.pm,v 1.101 2009/12/27 22:26:28 espie Exp $
#
# Copyright (c) 2005-2007 Marc Espie <espie@openbsd.org>
#
@@ -210,6 +210,36 @@ sub new
deplist => [], to_register => {}, all_dependencies => {} }, $class;
}
+sub check_for_loops
+{
+ my ($self, $state) = @_;
+
+ my $initial = $self->{set};
+
+ my @todo = ();
+ push(@todo, $initial);
+ my $done = {};
+
+ while (my $set = shift @todo) {
+ next unless defined $set->{solver};
+ for my $l (@{$set->{solver}->{deplist}}) {
+ next if $done->{$l};
+ push(@todo, $l);
+ if ($l eq $initial) {
+ my $k = $set;
+ while ($k ne $initial) {
+ $initial->merge($state->tracker, $k);
+ $k = $done->{$k};
+ }
+ $state->say("Merging ", $initial->print, $state->ntogo);
+ return 1;
+ }
+ $done->{$l} = $set;
+ }
+ }
+ return 0;
+}
+
sub dependencies
{
my $self = shift;
@@ -347,6 +377,7 @@ sub solve_depends
my ($self, $state) = @_;
for my $package ($self->{set}->newer) {
+ $package->{before} = [];
for my $dep (@{$package->{plist}->{depend}}) {
my $v = $self->solve_dependency($state, $dep, $package);
$self->{all_dependencies}->{$v} = $dep;