From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CA1A81F567 for ; Fri, 22 Sep 2023 21:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1695417196; bh=Km6+qZx9AjejtVjXMlkJOsJ7tYc+UQxhIJRg9mYmUYM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Mgyu4zHU6txOlERi4mo/fY8MKzI62ixm9pkDL1VpdvgUFYooH5+qWSyeuLAtD7iUc cMjX6r8l+HFVBuZXgW6tPDJlt9UpTUf6nqI4WJtR4+rZt81EBwUY7KUiFhhr0TKl7t w57e7TGJKJsPgQBHB2G3O8jtvBcJSAwXz62EkHKA= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/4] lei: use File::Temp for listing saved searches Date: Fri, 22 Sep 2023 21:13:16 +0000 Message-ID: <20230922211316.3060039-5-e@80x24.org> In-Reply-To: <20230922211316.3060039-1-e@80x24.org> References: <20230922211316.3060039-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: I have no idea how badly my brain malfunctioned here when I wrote the code to create a temporary file without O_EXCL :x I'm still not sure if users have enough saved searches for justifying a cache, here. --- lib/PublicInbox/LeiSavedSearch.pm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index e5396342..2811c46d 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -3,8 +3,7 @@ # pretends to be like LeiDedupe and also PublicInbox::Inbox package PublicInbox::LeiSavedSearch; -use strict; -use v5.10.1; +use v5.12; use parent qw(PublicInbox::Lock); use PublicInbox::Git; use PublicInbox::OverIdx; @@ -14,6 +13,8 @@ use PublicInbox::Spawn qw(run_die); use PublicInbox::ContentHash qw(git_sha); use PublicInbox::MID qw(mids_for_index); use PublicInbox::SHA qw(sha256_hex); +use File::Temp (); +use IO::Handle (); our $LOCAL_PFX = qr!\A(?:maildir|mh|mbox.+|mmdf|v2):!i; # TODO: put in LeiToMail? # move this to PublicInbox::Config if other things use it: @@ -76,20 +77,17 @@ sub list { my $lss_dir = $lei->share_path.'/saved-searches'; return () unless -d $lss_dir; # TODO: persist the cache? Use another format? - my $f = $lei->cache_dir."/saved-tmp.$$.".time.'.config'; - open my $fh, '>', $f or die "open $f: $!"; + my $fh = File::Temp->new(TEMPLATE => 'lss_list-XXXX', TMPDIR => 1) or + die "File::Temp->new: $!"; print $fh "[include]\n"; for my $p (glob("$lss_dir/*/lei.saved-search")) { print $fh "\tpath = ", cquote_val($p), "\n"; } - close $fh or die "close $f: $!"; - my $cfg = $lei->cfg_dump($f); - unlink($f); + $fh->flush or die "flush: $fh"; + my $cfg = $lei->cfg_dump($fh->filename); my $out = $cfg ? $cfg->get_all('lei.q.output') : []; - map {; - s!$LOCAL_PFX!!; - $_; - } @$out + s!$LOCAL_PFX!! for @$out;; + @$out; } sub translate_dedupe ($$) {