- if (@parts) {
- my $pid = spawn(['xapian-compact', @parts, "$new/0" ]);
- defined $pid or die "compact failed: $?\n";
- $pids{$pid} = 'xapian-compact (parts)';
- } else {
- warn "No parts found in $old\n";
- }
- if (defined $skel) {
- my $pid = spawn(['xapian-compact', $skel, "$new/skel"]);
- defined $pid or die "compact failed: $?\n";
- $pids{$pid} = 'xapian-compact (skel)';
- } else {
- warn "$old/skel missing\n";
- }
- scalar keys %pids or
- die "No xapian-compact processes running\n";
- while (scalar keys %pids) {
- my $pid = waitpid(-1, 0);
- my $desc = delete $pids{$pid};
- die "$desc failed: $?\n" if $?;
- }
- commit_changes($v2w, $old, $new);
- });
-} elsif ($v == 1) {
- require PublicInbox::Import;
- my $im = PublicInbox::Import->new($ibx->git, undef, undef, $ibx);
- my $xap_v = 'xapian'.PublicInbox::Search::SCHEMA_VERSION;
- my $v1_root = "$dir/public-inbox";
- my $old = "$v1_root/$xap_v";
- -d $old or die "$old does not exist\n";
- my $new = tempdir('compact-XXXXXXXX', CLEANUP => 1, DIR => $v1_root);
- $ibx->with_umask(sub {
- $im->lock_acquire;
- PublicInbox::Import::run_die(['xapian-compact', $old, $new]);
- commit_changes($im, $old, $new);
- });
-} else {
- die "Unsupported inbox version: $v\n";
+require PublicInbox::InboxWritable;
+require PublicInbox::Xapcmd;
+my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt);
+unless (@ibxs) { print STDERR "Usage: $usage\n"; exit 1 }
+foreach (@ibxs) {
+ my $ibx = PublicInbox::InboxWritable->new($_);
+ PublicInbox::Xapcmd::run($ibx, 'compact', $opt);