summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2004-12-27 22:16:14 +0000
committerMarc Espie <espie@cvs.openbsd.org>2004-12-27 22:16:14 +0000
commitb8d13cf22d45881ee605da9d46c097906ead5c12 (patch)
treeef7e45b5382cc24952af4ac3d99e8e0a3fc53658 /usr.sbin
parentc11e624119eaf661c820ea19b69a437e8ec0b83f (diff)
use delete, not undef, to update installed_packages correctly...
while we're there, clean-up code slightly.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm55
1 files changed, 30 insertions, 25 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index e6eed5776c5..e5db40c7500 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.14 2004/12/16 11:07:33 espie Exp $
+# $OpenBSD: PackageInfo.pm,v 1.15 2004/12/27 22:16:13 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -50,10 +50,35 @@ for my $i (@info) {
$info{$i} = $j;
}
+sub _init_list
+{
+ $list = {};
+ my @bad=();
+
+ opendir(my $dir, $pkg_db) or die "Bad pkg_db: $!";
+ while (my $e = readdir($dir)) {
+ next if $e eq '.' or $e eq '..';
+ next unless -d "$pkg_db/$e";
+ if (! -r _) {
+ push(@bad, $e);
+ next;
+ }
+ if (-f "$pkg_db/$e/+CONTENTS") {
+ $list->{$e} = 1;
+ } else {
+ print "Warning: $e is not really a package\n";
+ }
+ }
+ close($dir);
+ if (@bad > 0) {
+ print "Warning: can't access information for ", join(", ", @bad), "\n";
+ }
+}
+
sub add_installed
{
if (!defined $list) {
- installed_packages();
+ _init_list();
}
for my $p (@_) {
$list->{$p} = 1;
@@ -63,10 +88,10 @@ sub add_installed
sub delete_installed
{
if (!defined $list) {
- installed_packages();
+ _init_list();
}
for my $p (@_) {
- undef $list->{$p};
+ delete $list->{$p};
}
}
@@ -74,27 +99,7 @@ sub delete_installed
sub installed_packages(;$)
{
if (!defined $list) {
- $list = {};
- my @bad=();
-
- opendir(my $dir, $pkg_db) or die "Bad pkg_db: $!";
- while (my $e = readdir($dir)) {
- next if $e eq '.' or $e eq '..';
- next unless -d "$pkg_db/$e";
- if (! -r _) {
- push(@bad, $e);
- next;
- }
- if (-f "$pkg_db/$e/+CONTENTS") {
- $list->{$e} = 1;
- } else {
- print "Warning: $e is not really a package\n";
- }
- }
- close($dir);
- if (@bad > 0) {
- print "Warning: can't access information for ", join(", ", @bad), "\n";
- }
+ _init_list();
}
if ($_[0]) {
return grep { !/^\./ } keys %$list;