1 # Copyright (C) 2019-2021 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! help|h);
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 require PublicInbox::Search;
31 my $xdir_ro = PublicInbox::Search->new($ibx)->xdir(1);
34 foreach my $shard (<$xdir_ro/*>) {
35 if (-d $shard && $shard =~ m!/[0-9]+\z!) {
37 $bytes += -s $_ foreach glob("$shard/*");
42 PublicInbox::Admin::require_or_die('-search');
44 # somebody could "rm -r" all the Xapian directories;
45 # let them purge the overview, at least
46 $ibx->{indexlevel} ||= 'basic';
51 # takes the output of V2Writable::purge and V2Writable::replace
52 # $rewrites = [ array commits keyed by epoch ]
53 sub show_rewrites ($$$) {
54 my ($fh, $ibx, $rewrites) = @_;
55 print $fh "$ibx->{inboxdir}:";
56 if (scalar @$rewrites) {
60 "$epoch.git: ".(defined($_) ? $_ : '(unchanged)')
62 print $fh join("\n\t", '', @out), "\n";