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-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 789291FA11 for ; Mon, 10 Aug 2020 02:12:06 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/14] msgmap: tmp_clone: simplify + meaningful filename Date: Mon, 10 Aug 2020 02:11:57 +0000 Message-Id: <20200810021205.18909-7-e@yhbt.net> In-Reply-To: <20200810021205.18909-1-e@yhbt.net> References: <20200810021205.18909-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Trying to use the newer ->sqlite_backup_to_dbh method doesn't seem worth it, as we'll have to support DBD::SQLite <= 1.60 another decade or more. Dumping 'msgmap-XXXXXXX' into $INBOX_DIR can appear a bit confusing to users, so give it a "mm_tmp-$PID-XXXXXXXX" name to emphasize it's a temporary file tied to a given PID. We also don't want to penalize read-only daemons with loading File::Temp, so do it lazily. --- lib/PublicInbox/Msgmap.pm | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm index e7f7e2c9..7290959d 100644 --- a/lib/PublicInbox/Msgmap.pm +++ b/lib/PublicInbox/Msgmap.pm @@ -9,10 +9,8 @@ # This is maintained by ::SearchIdx package PublicInbox::Msgmap; use strict; -use warnings; use DBI; use DBD::SQLite; -use File::Temp qw(tempfile); use PublicInbox::Over; use PublicInbox::Spawn; @@ -50,18 +48,13 @@ sub new_file { # used to keep track of used numeric mappings for v2 reindex sub tmp_clone { my ($self, $dir) = @_; - my ($fh, $fn) = tempfile('msgmap-XXXXXXXX', EXLOCK => 0, DIR => $dir); + require File::Temp; + my $tmp = "mm_tmp-$$-XXXXXX"; + my ($fh, $fn) = File::Temp::tempfile($tmp, EXLOCK => 0, DIR => $dir); PublicInbox::Spawn::nodatacow_fd(fileno($fh)); - my $tmp; - if ($self->{dbh}->can('sqlite_backup_to_dbh')) { - $tmp = ref($self)->new_file($fn, 2); - $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY'); - $self->{dbh}->sqlite_backup_to_dbh($tmp->{dbh}); - } else { # DBD::SQLite <= 1.61_01 - $self->{dbh}->sqlite_backup_to_file($fn); - $tmp = ref($self)->new_file($fn, 2); - $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY'); - } + $self->{dbh}->sqlite_backup_to_file($fn); + $tmp = ref($self)->new_file($fn, 2); + $tmp->{dbh}->do('PRAGMA journal_mode = MEMORY'); $tmp->{pid} = $$; $tmp; }