From b5c64fc01d3e7ca6243fdd8b811b6291bdb12235 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 15 May 2019 01:18:10 +0000 Subject: searchidx: do not create empty Xapian partitions for basic No point in leaving a mess of empty directories when Xapian doesn't load. --- lib/PublicInbox/SearchIdx.pm | 7 ++++++- t/indexlevels-mirror.t | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 135b5eb9..f96f0d03 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -110,7 +110,12 @@ sub _xdb_acquire { if ($self->{creat}) { require File::Path; $self->lock_acquire; - File::Path::mkpath($dir); + + # don't create empty Xapian directories if we don't need Xapian + my $is_part = defined($self->{partition}); + if (!$is_part || ($is_part && need_xapian($self))) { + File::Path::mkpath($dir); + } } return unless defined $flag; $self->{xdb} = Search::Xapian::WritableDatabase->new($dir, $flag); diff --git a/t/indexlevels-mirror.t b/t/indexlevels-mirror.t index cac7050b..3dd43238 100644 --- a/t/indexlevels-mirror.t +++ b/t/indexlevels-mirror.t @@ -116,6 +116,11 @@ sub import_index_incremental { is($nr, 1, '2nd message gone from mirror'); is_deeply([map { $_->{mid} } @$msgs], ['m@1'], 'message unavailable in mirror'); + + if ($v == 2 && $level eq 'basic') { + is_deeply([glob("$ibx->{mainrepo}/xap*/?/")], [], + 'no Xapian partition directories for v2 basic'); + } } # we can probably cull some other tests and put full/medium tests, here -- cgit v1.2.3-24-ge0c7