summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2007-05-14 10:00:09 +0000
committerMarc Espie <espie@cvs.openbsd.org>2007-05-14 10:00:09 +0000
commit4eb45a02d3106a414c165c9bbf9d188474aaa8df (patch)
tree4a7fc95d68fe3712dd19ebcd4c30cad3be1c75fc
parent9f3ff678da304f25a7b5583c667e4dff7d39f58e (diff)
maintain stemlist for installed packages dynamically
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm16
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageName.pm19
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository.pm7
3 files changed, 36 insertions, 6 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index e9c47f0316c..acdd0dd9d87 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.25 2007/05/14 09:49:27 espie Exp $
+# $OpenBSD: PackageInfo.pm,v 1.26 2007/05/14 10:00:08 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -19,7 +19,7 @@ use strict;
use warnings;
package OpenBSD::PackageInfo;
our @ISA=qw(Exporter);
-our @EXPORT=qw(installed_packages installed_info installed_name info_names is_info_name
+our @EXPORT=qw(installed_packages installed_info installed_name info_names is_info_name installed_stems
lock_db unlock_db
add_installed delete_installed is_installed borked_package CONTENTS COMMENT DESC INSTALL DEINSTALL REQUIRE MODULE
REQUIRED_BY REQUIRING DISPLAY UNDISPLAY MTREE_DIRS);
@@ -42,7 +42,7 @@ use constant {
use Fcntl qw/:flock/;
my $pkg_db = $ENV{"PKG_DBDIR"} || '/var/db/pkg';
-my $list;
+my ($list, $stemlist);
our @info = (CONTENTS, COMMENT, DESC, REQUIRE, INSTALL, DEINSTALL, REQUIRED_BY, REQUIRING, DISPLAY, UNDISPLAY, MTREE_DIRS, MODULE);
@@ -57,11 +57,12 @@ for my $i (@info) {
sub _init_list
{
$list = {};
+ $stemlist = OpenBSD::PackageName::compile_stemlist();
opendir(my $dir, $pkg_db) or die "Bad pkg_db: $!";
while (my $e = readdir($dir)) {
next if $e eq '.' or $e eq '..';
- $list->{$e} = 1;
+ add_installed($e);
}
close($dir);
}
@@ -73,6 +74,7 @@ sub add_installed
}
for my $p (@_) {
$list->{$p} = 1;
+ $stemlist->add($p);
}
}
@@ -83,10 +85,16 @@ sub delete_installed
}
for my $p (@_) {
delete $list->{$p};
+ $stemlist->delete($p);
}
}
+sub installed_stems
+{
+ return $stemlist;
+}
+
sub installed_packages(;$)
{
if (!defined $list) {
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageName.pm b/usr.sbin/pkg_add/OpenBSD/PackageName.pm
index fc5e38fd075..e9c10232a1c 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageName.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageName.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageName.pm,v 1.22 2007/05/13 13:39:43 espie Exp $
+# $OpenBSD: PackageName.pm,v 1.23 2007/05/14 10:00:08 espie Exp $
#
# Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org>
#
@@ -153,6 +153,23 @@ sub find
return keys %{$self->{$stem}};
}
+sub add
+{
+ my ($self, $pkgname) = @_;
+ my $stem = OpenBSD::PackageName::splitstem($pkgname);
+ $self->{$stem}->{$pkgname} = 1;
+}
+
+sub delete
+{
+ my ($self, $pkgname) = @_;
+ my $stem = OpenBSD::PackageName::splitstem($pkgname);
+ delete $self->{$stem}->{$pkgname};
+ if(keys %{$self->{$stem}} == 0) {
+ delete $self->{$stem};
+ }
+}
+
sub find_partial
{
my ($self, $partial) = @_;
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
index ce389f8d360..25bcade9976 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepository.pm,v 1.29 2007/05/13 17:00:02 espie Exp $
+# $OpenBSD: PackageRepository.pm,v 1.30 2007/05/14 10:00:08 espie Exp $
#
# Copyright (c) 2003-2006 Marc Espie <espie@openbsd.org>
#
@@ -284,6 +284,11 @@ sub list
return \@list;
}
+sub stemlist
+{
+ return installed_stems();
+}
+
sub wipe_info
{
}