]> Sergey Matveev's repositories - public-inbox.git/blob - script/public-inbox-compact
xapcmd: new module for wrapping Xapian commands
[public-inbox.git] / script / public-inbox-compact
1 #!/usr/bin/perl -w
2 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use warnings;
6 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
7 use PublicInbox::Search;
8 use PublicInbox::Config;
9 use PublicInbox::InboxWritable;
10 use Cwd 'abs_path';
11 use PublicInbox::Xapcmd;
12 my $usage = "Usage: public-inbox-compact REPO_DIR\n";
13 my $dir = shift or die $usage;
14 my $config = eval { PublicInbox::Config->new };
15 my $ibx;
16 $dir = abs_path($dir);
17 if ($config) {
18         $config->each_inbox(sub {
19                 $ibx = $_[0] if abs_path($_[0]->{mainrepo}) eq $dir
20         });
21 }
22 unless ($ibx) {
23         warn "W: $dir not configured in ".
24                 PublicInbox::Config::default_file() . "\n";
25         $ibx = {
26                 mainrepo => $dir,
27                 name => 'ignored',
28                 address => [ 'old@example.com' ],
29         };
30         $ibx = PublicInbox::Inbox->new($ibx);
31 }
32 $ibx = PublicInbox::InboxWritable->new($ibx);
33
34 # we rely on --no-renumber to keep docids synched to NNTP
35 PublicInbox::Xapcmd::run($ibx, [qw(xapian-compact --no-renumber)]);