diff options
author | Eric Wong <e@80x24.org> | 2020-12-17 00:16:18 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2020-12-19 09:32:08 +0000 |
commit | 475e6b6a722361223505a7fcb084f5e729c69240 (patch) | |
tree | ee2b88ef6fc8bb659016b2a158d2bcaf8dc5b03c /lib/PublicInbox | |
parent | bcf5e76a87b46b038509b65ced64149e6d2b81c3 (diff) | |
download | public-inbox-475e6b6a722361223505a7fcb084f5e729c69240.tar.gz |
This follows how we detect the max epoch for v2 and shard count in Xapian.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/LeiStore.pm | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index b5b49efb..d3667d29 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -18,6 +18,7 @@ use PublicInbox::V2Writable; use PublicInbox::ContentHash qw(content_hash); use PublicInbox::MID qw(mids); use PublicInbox::LeiSearch; +use List::Util qw(max); sub new { my (undef, $dir, $opt) = @_; @@ -42,15 +43,13 @@ sub git_pfx { "$_[0]->{priv_eidx}->{topdir}/local" }; sub git_epoch_max { my ($self) = @_; - my $pfx = $self->git_pfx; - my $max = 0; - return $max unless -d $pfx ; - opendir my $dh, $pfx or die "opendir $pfx: $!\n"; - while (defined(my $git_dir = readdir($dh))) { - $git_dir =~ m!\A([0-9]+)\.git\z! or next; - $max = $1 + 0 if $1 > $max; + if (opendir(my $dh, $self->git_pfx)) { + max(map { + substr($_, 0, -4) + 0; # drop ".git" suffix + } grep(/\A[0-9]+\.git\z/, readdir($dh))) // 0; + } else { + $!{ENOENT} ? 0 : die("opendir ${\$self->git_pfx}: $!\n"); } - $max; } sub importer { |