user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 10/10] lei_ale: use v5.12, autodie, and try_cat
  2023-10-27 22:21  6% [PATCH 00/10] first steps towards eliminating TIEHANDLE Eric Wong
@ 2023-10-27 22:21  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-10-27 22:21 UTC (permalink / raw)
  To: meta

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;

^ permalink raw reply related	[relevance 7%]

* [PATCH 00/10] first steps towards eliminating TIEHANDLE
@ 2023-10-27 22:21  6% Eric Wong
  2023-10-27 22:21  7% ` [PATCH 10/10] lei_ale: use v5.12, autodie, and try_cat Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-10-27 22:21 UTC (permalink / raw)
  To: meta

ProcessIO being tied is problematic since perlops like stat
and fcntl don't work directly on the handle, and we need
separate classes to do buffered read and unbuffered sysread.

It's possible to do as common packages (e.g. File::Temp,
IO::Socket::IP, IO::Socket::SSL) do by subclassing IO::Handle
to avoid tie completely.  I also want to avoid the self-tie
thing IO::Socket::SSL to avoid having to rely on weaken().

So, this essentially becomes a war on `close($fh)' an relying
on $fh->close where appropriate.  This loses some usefulness
of autodie, so we keep `close($fh)' for places which aren't
tied at the moment.

One key place is to replace many calls to popen_rd with the new
run_qx to consolidate close calls.  There's also few other
cleanups, code reductions, and safety improvements along the way.

And more changes coming.

Eric Wong (10):
  spawn: croak directly in C pi_fork_exec
  spawnpp: use autodie for syscall failures
  spawn: avoid alloca in C pi_fork_exec
  git: use run_qx to read `git --version'
  git: avoid extra stat(2) for git version
  gcf2: simplify pkg-config and Inline::C setup
  treewide: use run_qx where appropriate
  www_altid: reduce FD pressure in qspawn queues
  xt/eml_check_limits: remove useless import
  lei_ale: use v5.12, autodie, and try_cat

 lib/PublicInbox/Admin.pm           |  7 ++---
 lib/PublicInbox/Config.pm          | 14 ++++-----
 lib/PublicInbox/Fetch.pm           |  7 ++---
 lib/PublicInbox/Gcf2.pm            | 27 +++++-----------
 lib/PublicInbox/Git.pm             | 15 +++++----
 lib/PublicInbox/Import.pm          |  6 ++--
 lib/PublicInbox/LEI.pm             |  7 ++---
 lib/PublicInbox/LeiALE.pm          | 24 +++++++--------
 lib/PublicInbox/LeiBlob.pm         | 12 +++-----
 lib/PublicInbox/LeiMirror.pm       |  7 ++---
 lib/PublicInbox/MultiGit.pm        |  7 ++---
 lib/PublicInbox/Spamcheck/Spamc.pm | 11 ++-----
 lib/PublicInbox/Spawn.pm           | 49 +++++++++++++++---------------
 lib/PublicInbox/SpawnPP.pm         | 10 +++---
 lib/PublicInbox/WwwAltId.pm        |  9 ++----
 lib/PublicInbox/XapHelperCxx.pm    | 11 ++-----
 t/solver_git.t                     | 12 +++-----
 xt/eml_check_limits.t              |  4 +--
 18 files changed, 94 insertions(+), 145 deletions(-)


^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-10-27 22:21  6% [PATCH 00/10] first steps towards eliminating TIEHANDLE Eric Wong
2023-10-27 22:21  7% ` [PATCH 10/10] lei_ale: use v5.12, autodie, and try_cat Eric Wong

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).