about summary refs log tree commit homepage
path: root/lib/PublicInbox/Xapcmd.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-23 09:37:02 +0000
committerEric Wong <e@80x24.org>2019-05-23 17:43:51 +0000
commitea3528394f0ee5c47f9b94a4d92d129c709990df (patch)
tree4509c36dd840653d28f918146c93e67edc083888 /lib/PublicInbox/Xapcmd.pm
parent0e41e076145c51f21151e29d64bd66cd3534d3ba (diff)
downloadpublic-inbox-ea3528394f0ee5c47f9b94a4d92d129c709990df.tar.gz
We should not have leftover junk on interrupted invocations.
Diffstat (limited to 'lib/PublicInbox/Xapcmd.pm')
-rw-r--r--lib/PublicInbox/Xapcmd.pm14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 74abf999..5b6d06b8 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -247,7 +247,16 @@ sub cpdb ($$) {
         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:
@@ -295,7 +304,7 @@ sub cpdb ($$) {
         } while (cpdb_retryable($src, $pfx));
 
         $pr->(sprintf($fmt, $nr)) if $pr;
-        return unless $opt->{compact};
+        return unless $xtmp;
 
         $src = $dst = undef; # flushes and closes
 
@@ -303,6 +312,7 @@ sub cpdb ($$) {
         # 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";
+        $xtmp->done;
 }
 
 # slightly easier-to-manage manage than END{} blocks