1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # common stuff between -edit, -purge (and maybe -learn in the future)
5 package PublicInbox::AdminEdit;
8 use PublicInbox::Admin;
9 our @OPT = qw(all force|f verbose|v!);
11 sub check_editable ($) {
14 foreach my $ibx (@$ibxs) {
15 my $lvl = $ibx->{indexlevel};
17 PublicInbox::Admin::indexlevel_ok_or_die($lvl);
21 # Undefined indexlevel, so `full'...
22 # Search::Xapian exists and the DB can be read, at least, fine
23 $ibx->search and next;
25 # it's possible for a Xapian directory to exist,
26 # but Search::Xapian to go missing/broken.
27 # Make sure it's purged in that case:
28 $ibx->over or die "no over.sqlite3 in $ibx->{inboxdir}\n";
30 # $ibx->{search} is populated by $ibx->over call
31 my $xdir_ro = $ibx->{search}->xdir(1);
33 foreach my $shard (<$xdir_ro/*>) {
34 if (-d $shard && $shard =~ m!/[0-9]+\z!) {
36 $bytes += -s $_ foreach glob("$shard/*");
41 PublicInbox::Admin::require_or_die('-search');
43 # somebody could "rm -r" all the Xapian directories;
44 # let them purge the overview, at least
45 $ibx->{indexlevel} ||= 'basic';
50 # takes the output of V2Writable::purge and V2Writable::replace
51 # $rewrites = [ array commits keyed by epoch ]
52 sub show_rewrites ($$$) {
53 my ($fh, $ibx, $rewrites) = @_;
54 print $fh "$ibx->{inboxdir}:";
55 if (scalar @$rewrites) {
59 "$epoch.git: ".(defined($_) ? $_ : '(unchanged)')
61 print $fh join("\n\t", '', @out), "\n";