We should not have leftover junk on interrupted invocations.
my ($args, $opt) = @_;
my ($old, $new) = @$args;
my $src = Search::Xapian::Database->new($old);
my ($args, $opt) = @_;
my ($old, $new) = @$args;
my $src = Search::Xapian::Database->new($old);
- my $tmp = $opt->{compact} ? "$new.compact" : $new;
+ my ($xtmp, $tmp);
+ if ($opt->{compact}) {
+ my $newdir = dirname($new);
+ same_fs_or_die($newdir, $new);
+ $tmp = tempdir("$new.compact-XXXXXX", DIR => $newdir);
+ $xtmp = PublicInbox::Xtmpdirs->new;
+ $xtmp->{$new} = $tmp;
+ } else {
+ $tmp = $new;
+ }
# like copydatabase(1), be sure we don't overwrite anything in case
# of other bugs:
# like copydatabase(1), be sure we don't overwrite anything in case
# of other bugs:
} while (cpdb_retryable($src, $pfx));
$pr->(sprintf($fmt, $nr)) if $pr;
} while (cpdb_retryable($src, $pfx));
$pr->(sprintf($fmt, $nr)) if $pr;
- return unless $opt->{compact};
$src = $dst = undef; # flushes and closes
$src = $dst = undef; # flushes and closes
# since $dst isn't readable by HTTP or NNTP clients, yet:
compact([ $tmp, $new ], $opt);
remove_tree($tmp) or die "failed to remove $tmp: $!\n";
# since $dst isn't readable by HTTP or NNTP clients, yet:
compact([ $tmp, $new ], $opt);
remove_tree($tmp) or die "failed to remove $tmp: $!\n";
}
# slightly easier-to-manage manage than END{} blocks
}
# slightly easier-to-manage manage than END{} blocks