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 86E431F406 for ; Fri, 27 Oct 2023 17:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698428437; bh=eRN82RV7rXY1NNpVgyppUzrvNsTF71IK+qlcb1/4/JE=; h=From:To:Subject:Date:From; b=vjnfEHQ3/l+qb9U+h5OxrEE3G5okavPKTmg9v9n0yVGgm6B4wji2wFBOuloIOXzGu JVkd03e6rh3SlXwnpddTJbrONAvHyGduE/GQq6X21FXWtYZR9MPD4RvpKGgXKScJi8 V/Z7pDvtJVSRBnMEc/fbAdw97hBlSFyIAtxSOR2E= From: Eric Wong To: spew@80x24.org Subject: [PATCH] lei_ale: use v5.12, autodie, and try_cat Date: Fri, 27 Oct 2023 17:40:37 +0000 Message-ID: <20231027174037.3853585-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: --- lib/PublicInbox/LeiALE.pm | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/LeiALE.pm b/lib/PublicInbox/LeiALE.pm index b198af1c..9743ecad 100644 --- a/lib/PublicInbox/LeiALE.pm +++ b/lib/PublicInbox/LeiALE.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # All Locals Ever: track lei/store + externals ever used as @@ -6,10 +6,10 @@ # and --only targets that haven't been through "lei add-external". # Typically: ~/.cache/lei/all_locals_ever.git package PublicInbox::LeiALE; -use strict; -use v5.10.1; +use v5.12; use parent qw(PublicInbox::LeiSearch PublicInbox::Lock); -use PublicInbox::Git qw(read_all); +use PublicInbox::Git; +use autodie qw(close open rename seek truncate); use PublicInbox::Import; use PublicInbox::LeiXSearch; use Fcntl qw(SEEK_SET); @@ -77,18 +77,16 @@ sub refresh_externals { if ($new ne '' || $gone) { $self->{lockfh}->autoflush(1); if ($gone) { - seek($self->{lockfh}, 0, SEEK_SET) or die "seek: $!"; - truncate($self->{lockfh}, 0) or die "truncate: $!"; + seek($self->{lockfh}, 0, SEEK_SET); + truncate($self->{lockfh}, 0); } else { $old = ''; } print { $self->{lockfh} } $old, $new or die "print: $!"; } - $new = $old = ''; + $new = ''; my $f = $self->git->{git_dir}.'/objects/info/alternates'; - if (open my $fh, '<', $f) { - read_all($fh, -s $fh, \$old); - } + $old = PublicInbox::Git::try_cat($f); for my $x (@ibxish) { $new .= $lei->canonpath_harder($x->git->{git_dir})."/objects\n"; } @@ -98,10 +96,10 @@ sub refresh_externals { # this needs to be atomic since child processes may start # git-cat-file at any time my $tmp = "$f.$$.tmp"; - open my $fh, '>', $tmp or die "open($tmp): $!"; - print $fh $new or die "print($tmp): $!"; - close $fh or die "close($tmp): $!"; - rename($tmp, $f) or die "rename($tmp, $f): $!"; + open my $fh, '>', $tmp; + print $fh $new; + close $fh; + rename($tmp, $f) } 1;