Skip to content

Commit 7b9b6a6

Browse files
committed
Add the ability to regenerate the index
1 parent 8ddc6cc commit 7b9b6a6

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PKG(8) - System Manager's Manual
1111
\[*info* *package*]
1212
\[*install* *package*]
1313
\[*pkginfo* *package*]
14+
\[*regen*]
1415
\[*search* *string*]
1516

1617
# DESCRIPTION
@@ -67,6 +68,12 @@ The options are as follows:
6768
> Aliased to
6869
> **pi**.
6970
71+
*regen*
72+
73+
> Regenerate the full text index.
74+
> Aliased to
75+
> **re**.
76+
7077
*search string*
7178

7279
> Search a packages

pkg.8

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
.Op Ar info Ar package
2727
.Op Ar install Ar package
2828
.Op Ar pkginfo Ar package
29+
.Op Ar regen
2930
.Op Ar search Ar string
3031
.Sh DESCRIPTION
3132
.Nm
@@ -73,6 +74,10 @@ for a given
7374
.Nm FULLPKGNAME .
7475
Aliased to
7576
.Nm pi .
77+
.It Ar regen
78+
Regenerate the full text index.
79+
Aliased to
80+
.Nm re .
7681
.It Ar search string
7782
Search a packages
7883
.Nm COMMENT

pkg.pl

+23-5
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@
2222

2323
$| = 1;
2424

25-
my @l = qw(add check create delete info search pkginfo);
25+
my @l = qw(add check create delete info search pkginfo regen);
26+
27+
# Commands that we wrap.
2628
my %a = (
2729
"del" => "delete",
2830
"i" => "add",
2931
"install" => "add",
3032
"rm" => "delete",
33+
"inf" => "info",
34+
);
3135

32-
"inf" => "info",
33-
"pi" => "pkginfo",
34-
"s" => "search"
36+
# Commands that are unique to pkg.
37+
my %b = (
38+
"pi" => "pkginfo",
39+
"re" => "regen",
40+
"s" => "search"
3541
);
3642

3743
my $srcDBfile = '/usr/local/share/sqlports';
@@ -46,7 +52,7 @@ sub run_sql {
4652
return $sth;
4753
}
4854

49-
if ( !-e $dbfile ) {
55+
sub createIDX {
5056
print STDERR "Creating full text database...";
5157
my $dbh = DBI->connect( "dbi:SQLite:dbname=:memory:", "", "" );
5258
run_sql( $dbh, "ATTACH DATABASE '$srcDBfile' AS ports;" );
@@ -84,10 +90,17 @@ sub run_sql {
8490
print STDERR "Done.\n";
8591
}
8692

93+
my $db_built = 0;
94+
if ( !-e $dbfile ) {
95+
$db_built = 1;
96+
createIDX();
97+
}
98+
8799
$dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "" );
88100

89101
sub run {
90102
my ( $cmd, $name ) = @_;
103+
return if $b{$name};
91104
my $module = "OpenBSD::Pkg\u$cmd";
92105
eval "require $module;";
93106
if ($@) {
@@ -107,6 +120,11 @@ sub run {
107120
$ARGV[0] = $a{ $ARGV[0] } if defined $a{ $ARGV[0] };
108121
if ( $ARGV[0] eq $i ) {
109122
shift;
123+
if ( $i eq "regen" && $db_built == 0 ) {
124+
unlink($dbfile);
125+
createIDX();
126+
exit();
127+
}
110128
if ( $i eq "pkginfo" ) {
111129

112130
# Take a FULLPKGNAME and return DESCR_CONTENTS and COMMENT

0 commit comments

Comments
 (0)