- $pr->(sprintf($fmt, $nr)) if $pr;
- return unless $xtmp;
-
- $src = $dst = undef; # flushes and closes
+# Like copydatabase(1), this is horribly slow; and it doesn't seem due
+# to the overhead of Perl.
+sub cpdb ($$) {
+ my ($args, $opt) = @_;
+ my ($old, $newdir) = @$args;
+ my $new = $newdir->dirname;
+ my ($src, $cur_shard);
+ my $reshard;
+ PublicInbox::SearchIdx::load_xapian_writable() or die;
+ my $XapianDatabase = $PublicInbox::Search::X{Database};
+ if (ref($old) eq 'ARRAY') {
+ ($cur_shard) = ($new =~ m!xap[0-9]+/([0-9]+)\b!);
+ defined $cur_shard or
+ die "BUG: could not extract shard # from $new";
+ $reshard = $opt->{reshard};
+ defined $reshard or die 'BUG: got array src w/o --reshard';
+
+ # resharding, M:N copy means have full read access
+ foreach (@$old) {
+ if ($src) {
+ my $sub = $XapianDatabase->new($_);
+ $src->add_database($sub);
+ } else {
+ $src = $XapianDatabase->new($_);
+ }
+ }
+ } else {
+ $src = $XapianDatabase->new($old);
+ }