Allow removal of entries.
--- a/exigrey.pl Wed Mar 18 14:50:22 2015 +0000
+++ b/exigrey.pl Tue May 24 16:32:18 2016 +0200
@@ -7,6 +7,7 @@
use constant USAGE => <<'#';
Usage: !ME! --insert item [delay [db]] # insert an item
+ !ME! --remove item # remove an item
!ME! --list [db] # list all items
!ME! --stat [db* ...] # print short statistic
!ME! --clean [days [db* ...]] # remove items not used since <days> days
@@ -43,6 +44,7 @@
my $opt_clean;
my $opt_purge;
my $opt_dbs;
+my $opt_remove;
sub getDBs(@);
sub iterate(\%$);
@@ -52,6 +54,7 @@
GetOptions(
"list!" => \$opt_list,
"insert!" => \$opt_insert,
+ "remove!" => \$opt_remove,
"stats!" => \$opt_stats,
"clean!" => \$opt_clean,
"purge!" => \$opt_purge,
@@ -161,10 +164,29 @@
print unseen(@ARGV);
exit 0;
}
+
+ if ($opt_remove) {
+ my %default = getDefault();
+ my $item = shift;
+ my $db = shift // $default{db};
+
+ my $key = "$item\0";
+
+ connectDB(\my %h, $db);
+ if (not exists $h{$key}) {
+ warn "$0: not found\n";
+ }
+ else {
+ $_ = delete $h{$key};
+ s/\0$/\n/;
+ print;
+ }
+ exit 0;
+ }
}
sub getDBs(@) {
- grep { -f }
+ grep { !/\.lock$/ } grep { -f -s }
map { m(^\.?/) ? glob($_) : glob(getDBDir() . "/$_") } @_ ? @_ : "*";
}