user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 10/10] lei_ale: use v5.12, autodie, and try_cat
Date: Fri, 27 Oct 2023 22:21:16 +0000	[thread overview]
Message-ID: <20231027222116.4034363-11-e@80x24.org> (raw)
In-Reply-To: <20231027222116.4034363-1-e@80x24.org>

Just things I spotted while looking for other problems
throughout our codebase.
---
 lib/PublicInbox/LeiALE.pm | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/LeiALE.pm b/lib/PublicInbox/LeiALE.pm
index b198af1c..674d897e 100644
--- a/lib/PublicInbox/LeiALE.pm
+++ b/lib/PublicInbox/LeiALE.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # 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 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;

      parent reply	other threads:[~2023-10-27 22:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-27 22:21 [PATCH 00/10] first steps towards eliminating TIEHANDLE Eric Wong
2023-10-27 22:21 ` [PATCH 01/10] spawn: croak directly in C pi_fork_exec Eric Wong
2023-10-27 22:21 ` [PATCH 02/10] spawnpp: use autodie for syscall failures Eric Wong
2023-10-27 22:21 ` [PATCH 03/10] spawn: avoid alloca in C pi_fork_exec Eric Wong
2023-10-27 22:21 ` [PATCH 04/10] git: use run_qx to read `git --version' Eric Wong
2023-10-27 22:21 ` [PATCH 05/10] git: avoid extra stat(2) for git version Eric Wong
2023-10-27 22:21 ` [PATCH 06/10] gcf2: simplify pkg-config and Inline::C setup Eric Wong
2023-10-27 22:21 ` [PATCH 07/10] treewide: use run_qx where appropriate Eric Wong
2023-10-27 22:21 ` [PATCH 08/10] www_altid: reduce FD pressure in qspawn queues Eric Wong
2023-10-27 22:21 ` [PATCH 09/10] xt/eml_check_limits: remove useless import Eric Wong
2023-10-27 22:21 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231027222116.4034363-11-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).