summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-11-14 11:40:09 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-11-14 11:40:09 +0000
commit599b3841e458d9cc111953cf698be7dd9d029e27 (patch)
tree406db10703d8f0365e24f24283d71e53606396da
parenta75c8bffb663109e44d930bc68b867987f46fe23 (diff)
let RequiredBy generate lists directly, use hashes to trim down duplicates directly. Optimize for !wantarray, by telling whether the list is empty or not.
prepare for a second similar list (REQUIRING) that will replace pkgdep, since pkg_add -r spends a hell of a lot of its time reading/writing long packing-lists... Use the simplified interface. Remove quite a few tests that the RequiredBy list is non-empty that do nothing but obfuscate the code: just deal with the damn list already.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm3
-rw-r--r--usr.sbin/pkg_add/OpenBSD/RequiredBy.pm61
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm45
-rw-r--r--usr.sbin/pkg_add/pkg_delete20
4 files changed, 67 insertions, 62 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index 75b674be01c..ac5dfa59780 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageInfo.pm,v 1.11 2004/11/11 11:54:09 espie Exp $
+# $OpenBSD: PackageInfo.pm,v 1.12 2004/11/14 11:40:08 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -32,6 +32,7 @@ use constant {
DEINSTALL => '+DEINSTALL',
REQUIRE => '+REQUIRE',
REQUIRED_BY => '+REQUIRED_BY',
+ REQUIRING => '+REQUIRING' ,
DISPLAY => '+DISPLAY',
UNDISPLAY => '+UNDISPLAY',
MTREE_DIRS => '+MTREE_DIRS' };
diff --git a/usr.sbin/pkg_add/OpenBSD/RequiredBy.pm b/usr.sbin/pkg_add/OpenBSD/RequiredBy.pm
index 0a613ca7e05..9ece6324f15 100644
--- a/usr.sbin/pkg_add/OpenBSD/RequiredBy.pm
+++ b/usr.sbin/pkg_add/OpenBSD/RequiredBy.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: RequiredBy.pm,v 1.4 2004/08/06 08:06:01 espie Exp $
+# $OpenBSD: RequiredBy.pm,v 1.5 2004/11/14 11:40:08 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -15,41 +15,39 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-package OpenBSD::RequiredBy;
use strict;
use warnings;
-use OpenBSD::PackageInfo;
-sub new
-{
- my ($class, $pkgname) = @_;
- my $f = installed_info($pkgname).REQUIRED_BY;
- bless \$f, $class;
-}
+package OpenBSD::RequirementList;
+use OpenBSD::PackageInfo;
sub list($)
{
my $self = shift;
- my $l = [];
- return $l unless -f $$self;
- open(my $fh, '<', $$self) or
- die "Problem opening required list: $$self: $!";
- local $_;
- while(<$fh>) {
- chomp $_;
- s/\s+$//;
- next if /^$/;
- push(@$l, $_);
+ if (wantarray) {
+ return () unless -f $$self;
+ open(my $fh, '<', $$self) or
+ die "Problem opening required list: $$self: $!";
+ local $_;
+ my $l = {};
+ while(<$fh>) {
+ chomp $_;
+ s/\s+$//;
+ next if /^$/;
+ $l->{$_} = 1;
+ }
+ close($fh);
+ return keys %$l;
+ } else {
+ return -f $$self ? 1 : 0;
}
- close($fh);
- return $l;
}
sub delete
{
my ($self, $pkgname) = @_;
- my @lines = grep { $_ ne $pkgname } @{$self->list()};
+ my @lines = grep { $_ ne $pkgname } $self->list();
unlink($$self) or die "Can't erase $$self: $!";
if (@lines > 0) {
$self->add(@lines);
@@ -65,4 +63,23 @@ sub add
close($fh);
}
+sub new
+{
+ my ($class, $pkgname) = @_;
+ my $f = installed_info($pkgname).$class->filename();
+ bless \$f, $class;
+}
+
+package OpenBSD::RequiredBy;
+our @ISA=qw(OpenBSD::RequirementList);
+use OpenBSD::PackageInfo;
+
+sub filename() { REQUIRED_BY };
+
+package OpenBSD::Requiring;
+our @ISA=qw(OpenBSD::RequirementList);
+use OpenBSD::PackageInfo;
+
+sub filename() { REQUIRING };
+
1;
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index 8dc41005f3e..cbd4712355e 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.30 2004/11/13 12:53:01 espie Exp $
+# $OpenBSD: Update.pm,v 1.31 2004/11/14 11:40:08 espie Exp $
#
# Copyright (c) 2004 Marc Espie <espie@openbsd.org>
#
@@ -199,8 +199,6 @@ sub can_do
{
my ($toreplace, $replacement, $state) = @_;
- my $wantlist = [];
- my $r = OpenBSD::RequiredBy->new($toreplace);
$state->{okay} = 1;
$state->{libs_to_check} = [];
my $plist = OpenBSD::PackingList->from_installation($toreplace);
@@ -211,17 +209,12 @@ sub can_do
if ($state->{forced}->{update}) {
$state->{okay} = 1;
}
- if (-f $$r) {
- $wantlist = $r->list();
- my $done_wanted = {};
- for my $wanting (@$wantlist) {
- next if defined $done_wanted->{$wanting};
- $done_wanted->{$wanting} = 1;
- print "Verifying dependencies still match for $wanting\n" if $state->{verbose};
- my $p2 = OpenBSD::PackingList->from_installation($wanting,
- \&OpenBSD::PackingList::DependOnly);
- $p2->visit('validate_depend', $state, $wanting, $toreplace, $replacement);
- }
+ my @wantlist = OpenBSD::RequiredBy->new($toreplace)->list();
+ for my $wanting (@wantlist) {
+ print "Verifying dependencies still match for $wanting\n" if $state->{verbose};
+ my $p2 = OpenBSD::PackingList->from_installation($wanting,
+ \&OpenBSD::PackingList::DependOnly);
+ $p2->visit('validate_depend', $state, $wanting, $toreplace, $replacement);
}
if ($state->{forced}->{updatedepends}) {
@@ -235,7 +228,7 @@ sub can_do
return 0;
}
- $plist->{wantlist} = $wantlist;
+ $plist->{wantlist} = \@wantlist;
$plist->{libs_to_check} = $state->{libs_to_check};
return $state->{okay} ? $plist : 0;
@@ -292,19 +285,15 @@ sub walk_depends_closure
while (my $pkg = shift @todo) {
$done->{$pkg} = 1;
- my $r = OpenBSD::RequiredBy->new($pkg);
- if (-f $$r) {
- my $list = $r->list();
- for my $pkg2 (@$list) {
- next if $done->{$pkg2};
- push(@todo, $pkg2);
- print "\t$pkg2\n" if $state->{beverbose};
- $write->add($pkg2) unless $state->{not};
- my $plist = OpenBSD::PackingList->from_installation($pkg2);
- OpenBSD::PackingElement::PkgDep->add($plist, $name);
- $plist->to_installation() unless $state->{not};
- $done->{$pkg2} = 1;
- }
+ for my $pkg2 (OpenBSD::RequiredBy->new($pkg)->list()) {
+ next if $done->{$pkg2};
+ push(@todo, $pkg2);
+ print "\t$pkg2\n" if $state->{beverbose};
+ $write->add($pkg2) unless $state->{not};
+ my $plist = OpenBSD::PackingList->from_installation($pkg2);
+ OpenBSD::PackingElement::PkgDep->add($plist, $name);
+ $plist->to_installation() unless $state->{not};
+ $done->{$pkg2} = 1;
}
}
}
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 4df5c5df85f..d135a909367 100644
--- a/usr.sbin/pkg_add/pkg_delete
+++ b/usr.sbin/pkg_add/pkg_delete
@@ -1,6 +1,6 @@
#!/usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_delete,v 1.75 2004/11/11 16:28:57 espie Exp $
+# $OpenBSD: pkg_delete,v 1.76 2004/11/14 11:40:08 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -125,14 +125,11 @@ for my $pkgname (@realnames) {
push(@todo, @realnames);
while (my $pkgname = pop @todo) {
- my $deps = OpenBSD::RequiredBy->new($pkgname)->list();
- if (@$deps > 0) {
- for my $dep (@$deps) {
- next if defined $toremove{$dep};
- next if defined $extra_rm{$dep};
- $extra_rm{$dep}=$pkgname;
- push(@todo, $dep);
- }
+ for my $dep (OpenBSD::RequiredBy->new($pkgname)->list()) {
+ next if defined $toremove{$dep};
+ next if defined $extra_rm{$dep};
+ $extra_rm{$dep}=$pkgname;
+ push(@todo, $dep);
}
}
@@ -170,8 +167,9 @@ eval {
$removed++;
next;
}
- my $deps = OpenBSD::RequiredBy->new($pkgname)->list();
- next if @$deps > 0;
+ if (OpenBSD::RequiredBy->new($pkgname)->list() > 0) {
+ next;
+ }
if (!OpenBSD::ProgressMeter::set_header($pkgname)) {
print $opt_n ? "Pretending to delete " : "Deleting ",
"$pkgname\n";