* [PATCH 3/5] check defined return value for localized slurp errors
2020-12-27 2:53 7% [PATCH 0/5] some yak shaving Eric Wong
@ 2020-12-27 2:53 6% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-12-27 2:53 UTC (permalink / raw)
To: meta
Reading from regular files (even on STDIN) can fail
when dealing with flakey storage.
---
lib/PublicInbox/Gcf2.pm | 2 +-
lib/PublicInbox/Inbox.pm | 9 +++------
script/public-inbox-edit | 3 ++-
script/public-inbox-init | 6 +-----
script/public-inbox-learn | 3 +--
script/public-inbox-purge | 2 +-
6 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/lib/PublicInbox/Gcf2.pm b/lib/PublicInbox/Gcf2.pm
index 041dffe7..fe6afef2 100644
--- a/lib/PublicInbox/Gcf2.pm
+++ b/lib/PublicInbox/Gcf2.pm
@@ -35,7 +35,7 @@ BEGIN {
if (open(my $fh, '<', $f)) {
chomp($l, $c);
local $/;
- $c_src = <$fh>;
+ defined($c_src = <$fh>) or die "read $f: $!\n";
$CFG{LIBS} = $l;
$CFG{CCFLAGSEX} = $c;
last;
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 1b9b56ff..af6380a7 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -210,12 +210,9 @@ sub over {
sub try_cat {
my ($path) = @_;
- my $rv = '';
- if (open(my $fh, '<', $path)) {
- local $/;
- $rv = <$fh>;
- }
- $rv;
+ open(my $fh, '<', $path) or return '';
+ local $/;
+ <$fh> // '';
}
sub cat_desc ($) {
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index a70614fc..81f023bc 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -183,7 +183,8 @@ retry_edit:
# rename/relink $edit_fn
open my $new_fh, '<', $edit_fn or
die "can't read edited file ($edit_fn): $!\n";
- my $new_raw = do { local $/; <$new_fh> };
+ defined(my $new_raw = do { local $/; <$new_fh> }) or die
+ "read $edit_fn: $!\n";
if (!$opt->{raw}) {
# get rid of the From we added
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 6d538e43..7ac77830 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -100,11 +100,7 @@ if (-e $pi_config) {
defined $perm or die "(f)stat failed on $pi_config: $!\n";
chmod($perm & 07777, $fh) or
die "(f)chmod failed on future $pi_config: $!\n";
- my $old;
- {
- local $/;
- $old = <$oh>;
- }
+ defined(my $old = do { local $/; <$oh> }) or die "read $pi_config: $!\n";
print $fh $old or die "failed to write: $!\n";
close $oh or die "failed to close $pi_config: $!\n";
diff --git a/script/public-inbox-learn b/script/public-inbox-learn
index 9352c8ff..1731a4ba 100755
--- a/script/public-inbox-learn
+++ b/script/public-inbox-learn
@@ -39,8 +39,7 @@ my $spamc = PublicInbox::Spamcheck::Spamc->new;
my $pi_cfg = PublicInbox::Config->new;
my $err;
my $mime = PublicInbox::Eml->new(do{
- local $/;
- my $data = <STDIN>;
+ defined(my $data = do { local $/; <STDIN> }) or die "read STDIN: $!\n";
$data =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
if ($train ne 'rm') {
diff --git a/script/public-inbox-purge b/script/public-inbox-purge
index 7bca11ea..52f1f18a 100755
--- a/script/public-inbox-purge
+++ b/script/public-inbox-purge
@@ -32,7 +32,7 @@ if ($opt->{help}) { print $help; exit 0 };
my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt);
PublicInbox::AdminEdit::check_editable(\@ibxs);
-my $data = do { local $/; <STDIN> };
+defined(my $data = do { local $/; <STDIN> }) or die "read STDIN: $!\n";
$data =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
my $n_purged = 0;
^ permalink raw reply related [relevance 6%]
* [PATCH 0/5] some yak shaving
@ 2020-12-27 2:53 7% Eric Wong
2020-12-27 2:53 6% ` [PATCH 3/5] check defined return value for localized slurp errors Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-12-27 2:53 UTC (permalink / raw)
To: meta
Some minor things to fix some small annoyances; I needed a break
from other areas of the code.
Eric Wong (5):
git: qx: avoid extra "local" for scalar context case
import: check for git->qx errors, clearer return values
check defined return value for localized slurp errors
ds: simplify EventLoop implementation
ds: flatten + reuse @events, epoll_wait style fixes
lib/PublicInbox/DS.pm | 49 ++++++++--------------------
lib/PublicInbox/DSKQXS.pm | 2 +-
lib/PublicInbox/DSPoll.pm | 3 +-
lib/PublicInbox/Gcf2.pm | 2 +-
lib/PublicInbox/Git.pm | 6 ++--
lib/PublicInbox/Import.pm | 9 +++---
lib/PublicInbox/Inbox.pm | 9 ++----
lib/PublicInbox/Syscall.pm | 66 +++++++++++++++++++++-----------------
script/public-inbox-edit | 3 +-
script/public-inbox-init | 6 +---
script/public-inbox-learn | 3 +-
script/public-inbox-purge | 2 +-
t/ds-poll.t | 28 ++++++++--------
t/epoll.t | 8 ++---
t/git.t | 5 +++
15 files changed, 92 insertions(+), 109 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-12-27 2:53 7% [PATCH 0/5] some yak shaving Eric Wong
2020-12-27 2:53 6% ` [PATCH 3/5] check defined return value for localized slurp errors 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).