X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FAdmin.pm;h=a17a632ceb8606d8ded62ae3398f62609103a12b;hb=ef68ada3b207fdb511ebe6d33b072a84277e6cd6;hp=eb38dd8fd384e73ab3de4425258e065a2e1e4873;hpb=11e454643ca0a8556f972ba6954dfec3855c62e7;p=public-inbox.git diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index eb38dd8f..a17a632c 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -28,6 +28,27 @@ sub setup_signals { }; } +sub resolve_eidxdir { + my ($cd) = @_; + my $try = $cd // '.'; + my $root_dev_ino; + while (1) { # favor v2, first + if (-f "$try/ei.lock") { + return rel2abs_collapsed($try); + } elsif (-d $try) { + my @try = stat _; + $root_dev_ino //= do { + my @root = stat('/') or die "stat /: $!\n"; + "$root[0]\0$root[1]"; + }; + return undef if "$try[0]\0$try[1]" eq $root_dev_ino; + $try .= '/..'; # continue, cd up + } else { + die "`$try' is not a directory\n"; + } + } +} + sub resolve_inboxdir { my ($cd, $ver) = @_; my $try = $cd // '.'; @@ -107,11 +128,24 @@ sub resolve_inboxes ($;$$) { $cfg or die "--all specified, but $cfgfile not readable\n"; @$argv and die "--all specified, but directories specified\n"; } - + my (@old, @ibxs, @eidx); + if ($opt->{-eidx_ok}) { + require PublicInbox::ExtSearchIdx; + my $i = -1; + @$argv = grep { + $i++; + if (defined(my $ei = resolve_eidxdir($_))) { + $ei = PublicInbox::ExtSearchIdx->new($ei, $opt); + push @eidx, $ei; + undef; + } else { + 1; + } + } @$argv; + } my $min_ver = $opt->{-min_inbox_version} || 0; # lookup inboxes by st_dev + st_ino instead of {inboxdir} pathnames, # pathnames are not unique due to symlinks and bind mounts - my (@old, @ibxs); if ($opt->{all}) { $cfg->each_inbox(sub { my ($ibx) = @_; @@ -161,11 +195,10 @@ sub resolve_inboxes ($;$$) { die "-V$min_ver inboxes not supported by $0\n\t", join("\n\t", @old), "\n"; } - @ibxs; + $opt->{-eidx_ok} ? (\@ibxs, \@eidx) : @ibxs; } -# TODO: make Devel::Peek optional, only used for daemon -my @base_mod = qw(Devel::Peek); +my @base_mod = (); my @over_mod = qw(DBD::SQLite DBI); my %mod_groups = ( -index => [ @base_mod, @over_mod ], @@ -240,14 +273,14 @@ sub index_inbox { if (my $pr = $opt->{-progress}) { $pr->("indexing $ibx->{inboxdir} ...\n"); } - local %SIG = %SIG; + local @SIG{keys %SIG} = values %SIG; setup_signals(\&index_terminate, $ibx); my $idx = { current_info => $ibx->{inboxdir} }; local $SIG{__WARN__} = sub { return if PublicInbox::Eml::warn_ignore(@_); warn($idx->{current_info}, ': ', @_); }; - if (ref($ibx) && $ibx->version == 2) { + if ($ibx->version == 2) { eval { require PublicInbox::V2Writable }; die "v2 requirements not met: $@\n" if $@; $ibx->{-creat_opt}->{nproc} = $jobs; @@ -335,7 +368,19 @@ sub index_prepare ($$) { or die "`$git_key=$s' not boolean\n"; $opt->{$k} = $v; } + for my $k (qw(since until)) { + my $v = $opt->{$k} // next; + $opt->{reindex} or die "--$k=$v requires --reindex\n"; + } $env; } +sub do_chdir ($) { + my $chdir = $_[0] // return; + for my $d (@$chdir) { + next if $d eq ''; # same as git(1) + chdir $d or die "cd $d: $!"; + } +} + 1;