From 05cffd40bf094355d19e12aac9a363e796da1702 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 12 Jun 2021 00:10:42 +0000 Subject: lei ls-mail-source: write through to URL folder cache We'll be able to use this for shell completion for lei import, lcat, tag, etc.. This also adds --url support for scripting purposes. --- lib/PublicInbox/SharedKV.pm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/SharedKV.pm') diff --git a/lib/PublicInbox/SharedKV.pm b/lib/PublicInbox/SharedKV.pm index d65c3158..8347b195 100644 --- a/lib/PublicInbox/SharedKV.pm +++ b/lib/PublicInbox/SharedKV.pm @@ -11,7 +11,7 @@ use parent qw(PublicInbox::Lock); use File::Temp qw(tempdir); use DBI (); use PublicInbox::Spawn; -use File::Path qw(rmtree); +use File::Path qw(rmtree make_path); sub dbh { my ($self, $lock) = @_; @@ -46,8 +46,8 @@ CREATE TABLE IF NOT EXISTS kv ( sub new { my ($cls, $dir, $base, $opt) = @_; my $self = bless { opt => $opt }, $cls; + make_path($dir) if defined($dir) && !-d $dir; $dir //= $self->{"tmp$$.$self"} = tempdir("skv.$$-XXXX", TMPDIR => 1); - -d $dir or mkdir($dir) or die "mkdir($dir): $!"; $base //= ''; my $f = $self->{filename} = "$dir/$base.sqlite3"; $self->{lock_path} = $opt->{lock_path} // "$dir/$base.flock"; @@ -83,6 +83,15 @@ SELECT k,v FROM kv $sth } +sub keys { + my ($self) = @_; + my $sth = $self->dbh->prepare_cached(<<'', undef, 1); +SELECT k FROM kv + + $sth->execute; + map { $_->[0] } @{$sth->fetchall_arrayref}; +} + sub delete_by_val { my ($self, $val, $lock) = @_; $lock //= $self->lock_for_scope_fast; -- cgit v1.2.3-24-ge0c7