summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2004-12-19 14:09:53 +0000
committerespie <espie@openbsd.org>2004-12-19 14:09:53 +0000
commit98ba5788eeb19c55f99468b01ab367e902115482 (patch)
tree95b50c85e24c7b5cd2d1e9848d31e6a86737e451
parentfix cleanup (diff)
downloadwireguard-openbsd-98ba5788eeb19c55f99468b01ab367e902115482.tar.xz
wireguard-openbsd-98ba5788eeb19c55f99468b01ab367e902115482.zip
move conflict code to PkgCfl.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgCfl.pm54
-rw-r--r--usr.sbin/pkg_add/pkg_add40
2 files changed, 56 insertions, 38 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm
index b1d8dc19ccc..0870aadf394 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgCfl.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PkgCfl.pm,v 1.8 2004/12/16 11:30:16 espie Exp $
+# $OpenBSD: PkgCfl.pm,v 1.9 2004/12/19 14:09:53 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -21,6 +21,7 @@ use warnings;
package OpenBSD::PkgCfl;
use OpenBSD::PackageName;
use OpenBSD::PkgSpec;
+use OpenBSD::PackageInfo;
sub glob2re
{
@@ -69,4 +70,55 @@ sub conflicts_with
return @l;
}
+sub register($$)
+{
+ my ($plist, $state) = @_;
+ $state->{conflict_list}->{$plist->pkgname()} = $plist->{conflicts};
+}
+
+sub fill_conflict_lists($)
+{
+ my $state = shift;
+ for my $pkg (installed_packages()) {
+ my $plist = OpenBSD::PackingList->from_installation($pkg,
+ \&OpenBSD::PackingList::ConflictOnly);
+ next unless defined $plist;
+ $plist->{conflicts} = OpenBSD::PkgCfl->make_conflict_list($plist);
+ register($plist, $state);
+ }
+}
+
+sub find($$)
+{
+ my ($pkgname, $state) = @_;
+ my @bad = ();
+ if (is_installed $pkgname) {
+ push(@bad, $pkgname);
+ }
+ if (!defined $state->{conflict_list}) {
+ $state->{conflict_list} = {};
+ fill_conflict_lists($state);
+ }
+ while (my ($name, $l) = each %{$state->{conflict_list}}) {
+ next if $name eq $pkgname;
+ if ($l->conflicts_with($pkgname)) {
+ push(@bad, $name);
+ }
+ }
+ return @bad;
+}
+
+sub find_all
+{
+ my ($plist, $state) = @_;
+ my $pkgname = $plist->pkgname();
+
+ my $l = OpenBSD::PkgCfl->make_conflict_list($plist);
+ $plist->{conflicts} = $l;
+
+ my @conflicts = find($pkgname, $state);
+ push(@conflicts, $l->conflicts_with(installed_packages()));
+ return @conflicts;
+}
+
1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index 6d7c889dc0c..2cc86fd8e92 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.150 2004/12/18 14:40:27 espie Exp $
+# $OpenBSD: pkg_add,v 1.151 2004/12/19 14:09:53 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -38,46 +38,14 @@ our %forced = ();
package main;
our $not;
-sub fill_conflict_lists
-{
- my $state = shift;
- # first, find all possible potential conflicts
- for my $pkg (installed_packages()) {
- my $plist = OpenBSD::PackingList->from_installation($pkg,
- \&OpenBSD::PackingList::ConflictOnly);
- next unless defined $plist;
- $state->{conflict_list}->{$plist->pkgname()} =
- OpenBSD::PkgCfl->make_conflict_list($plist);
- }
-}
-
my $errors = 0;
-sub find_conflicts($$)
-{
- my ($pkgname, $state) = @_;
- my @bad = ();
- if (is_installed $pkgname) {
- push(@bad, $pkgname);
- }
- while (my ($name, $l) = each %{$state->{conflict_list}}) {
- next if $name eq $pkgname;
- if ($l->conflicts_with($pkgname)) {
- push(@bad, $name);
- }
- }
- return @bad;
-}
sub can_install($$$)
{
my ($plist, $state, $handle) = @_;
my $pkgname = $plist->pkgname();
- my $l = OpenBSD::PkgCfl->make_conflict_list($plist);
- $handle->{conflicts} = $l;
-
- my @conflicts = find_conflicts($pkgname, $state);
- push(@conflicts, $l->conflicts_with(installed_packages()));
+ my @conflicts = OpenBSD::PkgCfl::find_all($plist, $state);
return 1 if @conflicts == 0;
my %conflicts = map {($_,1)} @conflicts;
@@ -637,7 +605,7 @@ sub install_package
}
}
really_add($handle, $state);
- $state->{conflict_list}->{$plist->pkgname()} = $handle->{conflicts};
+ OpenBSD::PkgCfl::register($plist, $state);
return ();
}
@@ -717,7 +685,6 @@ if (defined $state->{destdir}) {
}
-$state->{conflict_list} = {};
$state->{not} = $opt_n;
$not = $opt_n;
$state->{quick} = $opt_q;
@@ -739,7 +706,6 @@ if ($< && !$forced{nonroot}) {
}
}
-fill_conflict_lists($state);
my @todo = (@ARGV);
if (defined $state->{forced}->{kitchensink}) {
reorder(\@todo);