From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 419962067C for ; Thu, 23 May 2019 09:37:14 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 24/26] xapcmd: cleanup on interrupted xcpdb "--compact" Date: Thu, 23 May 2019 09:37:02 +0000 Message-Id: <20190523093704.18367-25-e@80x24.org> In-Reply-To: <20190523093704.18367-1-e@80x24.org> References: <20190523093704.18367-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We should not have leftover junk on interrupted invocations. --- lib/PublicInbox/Xapcmd.pm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index 74abf99..5b6d06b 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 -- EW