* [PATCH 00/14] various odds and ends
@ 2025-01-18 1:26 Eric Wong
2025-01-18 1:26 ` [PATCH 01/14] inbox_writable: use autodie::open Eric Wong
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
A bunch of other things I noticed while working on other things
and being annoyed by test suite slowness...
Eric Wong (14):
inbox_writable: use autodie::open
v2writable: simplify ->new by reducing arg flexibility
inbox_writable: match v1 and v2 init semantics
init: move --skip-artnum handling to {-creat_opt}
init: move --skip-epoch handling to {-creat_opt}
lei_saved_search: drop needless comparisons and `next'
treewide: replace redundant `;;' with `;'
lei_xsearch: use autodie for `pipe' ops
treewide: use autodie for seek+sysseek
git: rely on autodie for sysseek/sysread/truncate
config: config_fh_parse: hardcode FS/RS
v2writable: remove outdated FIXME comment and assertions
mda: use read_all for error handling
emergency: remove needless $! clobber
Documentation/common.perl | 3 ++-
lib/PublicInbox/Config.pm | 14 +++++++-------
lib/PublicInbox/Emergency.pm | 6 +++---
lib/PublicInbox/Git.pm | 14 ++++++++------
lib/PublicInbox/HTTP.pm | 5 +----
lib/PublicInbox/InboxWritable.pm | 28 +++++++++++-----------------
lib/PublicInbox/LeiSavedSearch.pm | 3 +--
lib/PublicInbox/LeiViewText.pm | 3 ++-
lib/PublicInbox/LeiXSearch.pm | 8 ++++----
lib/PublicInbox/SolverGit.pm | 4 ++--
lib/PublicInbox/V2Writable.pm | 17 +++++++----------
lib/PublicInbox/ViewVCS.pm | 9 ++++-----
lib/PublicInbox/WwwStatic.pm | 6 +++---
script/public-inbox-init | 12 ++++++------
script/public-inbox-mda | 3 +--
script/public-inbox-purge | 2 +-
scripts/import_vger_from_mbox | 2 +-
t/check-www-inbox.perl | 3 ++-
t/gcf2.t | 12 +++++++-----
t/gzip_filter.t | 2 +-
t/httpd-corner.t | 4 ++--
t/import.t | 3 ++-
t/ipc.t | 3 ++-
t/lei-daemon.t | 2 +-
t/lei-externals.t | 5 +++--
t/lei-p2q.t | 5 +++--
t/lei-sigpipe.t | 4 ++--
t/mbox_reader.t | 6 +++---
t/v2-add-remove-add.t | 2 +-
t/v2mirror.t | 2 +-
t/v2reindex.t | 8 ++++----
t/v2writable.t | 2 +-
32 files changed, 99 insertions(+), 103 deletions(-)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 01/14] inbox_writable: use autodie::open
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 02/14] v2writable: simplify ->new by reducing arg flexibility Eric Wong
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
autodie should give us more consistent error reporting going
forward.
---
lib/PublicInbox/InboxWritable.pm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index 18412cc3..f391d7ee 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -6,6 +6,7 @@ package PublicInbox::InboxWritable;
use strict;
use v5.10.1;
use parent qw(PublicInbox::Inbox PublicInbox::Umask Exporter);
+use autodie qw(open);
use PublicInbox::Import;
use PublicInbox::IO qw(read_all);
use PublicInbox::Filter::Base qw(REJECT);
@@ -49,8 +50,7 @@ sub _init_v1 {
undef $mm; # ->created_at set
$sidx->commit_txn_lazy;
} else {
- open my $fh, '>>', "$self->{inboxdir}/ssoma.lock" or
- die "$self->{inboxdir}/ssoma.lock: $!\n";
+ open my $fh, '>>', "$self->{inboxdir}/ssoma.lock";
}
}
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 02/14] v2writable: simplify ->new by reducing arg flexibility
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
2025-01-18 1:26 ` [PATCH 01/14] inbox_writable: use autodie::open Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 03/14] inbox_writable: match v1 and v2 init semantics Eric Wong
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
We can update callers easily enough for internal-only APIs,
so there's no need to deal with unwarranted flexibility for
V2Writable->new.
---
lib/PublicInbox/V2Writable.pm | 10 ++++------
script/public-inbox-purge | 2 +-
scripts/import_vger_from_mbox | 2 +-
t/v2-add-remove-add.t | 2 +-
t/v2mirror.t | 2 +-
t/v2reindex.t | 8 ++++----
t/v2writable.t | 2 +-
7 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 3f05d5a6..b5ed7c02 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -45,13 +45,11 @@ sub count_shards ($) {
}
sub new {
- # $creat may be any true value, or 0/undef. A hashref is true,
- # and $creat->{nproc} may be set to an integer
- my ($class, $v2ibx, $creat) = @_;
- $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
+ my ($class, $v2ibx, $creat_opt) = @_;
+ $v2ibx = PublicInbox::InboxWritable->new($v2ibx, $creat_opt);
my $dir = $v2ibx->assert_usable_dir;
unless (-d $dir) {
- die "$dir does not exist\n" if !$creat;
+ die "$dir does not exist\n" if !$creat_opt;
require File::Path;
File::Path::mkpath($dir);
}
@@ -72,7 +70,7 @@ sub new {
last_commit => [], # git epoch -> commit
};
$self->{oidx}->{-no_fsync} = 1 if $v2ibx->{-no_fsync};
- $self->{shards} = count_shards($self) || nproc_shards($creat);
+ $self->{shards} = count_shards($self) || nproc_shards($creat_opt);
bless $self, $class;
}
diff --git a/script/public-inbox-purge b/script/public-inbox-purge
index 381f58cd..0100cf48 100755
--- a/script/public-inbox-purge
+++ b/script/public-inbox-purge
@@ -39,7 +39,7 @@ my $n_purged = 0;
foreach my $ibx (@ibxs) {
my $eml = PublicInbox::Eml->new($data);
- my $v2w = PublicInbox::V2Writable->new($ibx, 0);
+ my $v2w = PublicInbox::V2Writable->new($ibx);
my $commits = $v2w->purge($eml) || [];
diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox
index 40ccf50b..bd086d9d 100644
--- a/scripts/import_vger_from_mbox
+++ b/scripts/import_vger_from_mbox
@@ -34,7 +34,7 @@ $ibx = PublicInbox::Inbox->new($ibx);
unless ($dry_run) {
if ($version >= 2) {
require PublicInbox::V2Writable;
- PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0);
+ PublicInbox::V2Writable->new($ibx, {})->init_inbox(0);
} else {
system(qw(git init --bare -q), $inboxdir) == 0 or die;
}
diff --git a/t/v2-add-remove-add.t b/t/v2-add-remove-add.t
index ddf8d248..070b1ac1 100644
--- a/t/v2-add-remove-add.t
+++ b/t/v2-add-remove-add.t
@@ -26,7 +26,7 @@ Message-ID: <a-mid@b>
hello world
EOF
-my $im = PublicInbox::V2Writable->new($ibx, 1);
+my $im = PublicInbox::V2Writable->new($ibx, { nproc => 1 });
$im->{parallel} = 0;
ok($im->add($mime), 'message added');
ok($im->remove($mime), 'message removed');
diff --git a/t/v2mirror.t b/t/v2mirror.t
index dd4d9a6c..9d8ba627 100644
--- a/t/v2mirror.t
+++ b/t/v2mirror.t
@@ -38,7 +38,7 @@ my $ibx = $cfg->lookup('test@example.com');
ok($ibx, 'inbox found');
$ibx->{version} = 2;
$ibx->{-no_fsync} = 1;
-my $v2w = PublicInbox::V2Writable->new($ibx, 1);
+my $v2w = PublicInbox::V2Writable->new($ibx, { nproc => 1 });
ok $v2w, 'v2w loaded';
$v2w->{parallel} = 0;
my $mime = PublicInbox::Eml->new(<<'');
diff --git a/t/v2reindex.t b/t/v2reindex.t
index 8c49e154..0e018481 100644
--- a/t/v2reindex.t
+++ b/t/v2reindex.t
@@ -78,7 +78,7 @@ my ($mark1, $mark2, $mark3, $mark4);
{
my %config = %$ibx_config;
my $ibx = PublicInbox::Inbox->new(\%config);
- my $im = PublicInbox::V2Writable->new($ibx, 1);
+ my $im = PublicInbox::V2Writable->new($ibx);
eval { $im->index_sync({reindex => 1}) };
is($@, '', 'no error from reindexing');
$im->done;
@@ -97,7 +97,7 @@ ok(!-d $xap, 'Xapian directories removed');
{
my %config = %$ibx_config;
my $ibx = PublicInbox::Inbox->new(\%config);
- my $im = PublicInbox::V2Writable->new($ibx, 1);
+ my $im = PublicInbox::V2Writable->new($ibx);
eval { $im->index_sync({reindex => 1}) };
is($@, '', 'no error from reindexing');
$im->done;
@@ -119,7 +119,7 @@ ok(!-d $xap, 'Xapian directories removed again');
local $SIG{__WARN__} = sub { push @warn, @_ };
my %config = %$ibx_config;
my $ibx = PublicInbox::Inbox->new(\%config);
- my $im = PublicInbox::V2Writable->new($ibx, 1);
+ my $im = PublicInbox::V2Writable->new($ibx);
eval { $im->index_sync({reindex => 1}) };
is($@, '', 'no error from reindexing without msgmap');
is(scalar(@warn), 0, 'no warnings from reindexing');
@@ -142,7 +142,7 @@ ok(!-d $xap, 'Xapian directories removed again');
local $SIG{__WARN__} = sub { push @warn, @_ };
my %config = %$ibx_config;
my $ibx = PublicInbox::Inbox->new(\%config);
- my $im = PublicInbox::V2Writable->new($ibx, 1);
+ my $im = PublicInbox::V2Writable->new($ibx);
eval { $im->index_sync({reindex => 1}) };
is($@, '', 'no error from reindexing without msgmap');
is_deeply(\@warn, [], 'no warnings');
diff --git a/t/v2writable.t b/t/v2writable.t
index 144ee685..242088f9 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -313,7 +313,7 @@ eval {
ok($@, 'V2Writable fails on non-existent dir');
{
- my $v2w = PublicInbox::V2Writable->new($tmp, 1);
+ my $v2w = PublicInbox::V2Writable->new($tmp, { nproc => 1 });
ok($v2w, 'creat flag works');
$v2w->{parallel} = 0;
$v2w->init_inbox(0);
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 03/14] inbox_writable: match v1 and v2 init semantics
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
2025-01-18 1:26 ` [PATCH 01/14] inbox_writable: use autodie::open Eric Wong
2025-01-18 1:26 ` [PATCH 02/14] v2writable: simplify ->new by reducing arg flexibility Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 04/14] init: move --skip-artnum handling to {-creat_opt} Eric Wong
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
More consistent code between v1 and v2 will make maintenance
easier going forward.
---
lib/PublicInbox/InboxWritable.pm | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index f391d7ee..1982ac05 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -16,14 +16,8 @@ use Fcntl qw(O_RDONLY O_NONBLOCK);
sub new {
my ($class, $ibx, $creat_opt) = @_;
- return $ibx if ref($ibx) eq $class;
- my $self = bless $ibx, $class;
-
- # TODO: maybe stop supporting this
- if ($creat_opt) { # for { nproc => $N }
- $self->{-creat_opt} = $creat_opt;
- init_inbox($self) if $self->version == 1;
- }
+ my $self = bless $ibx, $class; # idempotent
+ $self->{-creat_opt} = $creat_opt if $creat_opt; # for { nproc => $N }
$self;
}
@@ -77,8 +71,8 @@ sub importer {
$v2w->{parallel} = $parallel if defined $parallel;
$v2w;
} elsif ($v == 1) {
- my @arg = (undef, undef, undef, $self);
- PublicInbox::Import->new(@arg);
+ init_inbox($self) if $self->{-creat_opt};
+ PublicInbox::Import->new(undef, undef, undef, $self);
} else {
$! = 78; # EX_CONFIG 5.3.5 local configuration error
die "unsupported inbox version: $v\n";
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 04/14] init: move --skip-artnum handling to {-creat_opt}
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (2 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 03/14] inbox_writable: match v1 and v2 init semantics Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 05/14] init: move --skip-epoch " Eric Wong
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
It makes more sense to have inbox creation options bundled
together and reduces the amount of potentially confusing
positional parameters we must pass around.
---
lib/PublicInbox/InboxWritable.pm | 10 +++++-----
lib/PublicInbox/V2Writable.pm | 3 ++-
script/public-inbox-init | 8 ++++----
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index 1982ac05..a8239f49 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -29,7 +29,8 @@ sub assert_usable_dir {
}
sub _init_v1 {
- my ($self, $skip_artnum) = @_;
+ my ($self) = @_;
+ my $skip_artnum = ($self->{-creat_opt} // {})->{'skip-artnum'};
if (defined($self->{indexlevel}) || defined($skip_artnum)) {
require PublicInbox::SearchIdx;
require PublicInbox::Msgmap;
@@ -49,14 +50,13 @@ sub _init_v1 {
}
sub init_inbox {
- my ($self, $shards, $skip_epoch, $skip_artnum) = @_;
+ my ($self, $shards, $skip_epoch) = @_;
if ($self->version == 1) {
my $dir = assert_usable_dir($self);
PublicInbox::Import::init_bare($dir);
- $self->with_umask(\&_init_v1, $self, $skip_artnum);
+ $self->with_umask(\&_init_v1, $self);
} else {
- my $v2w = importer($self);
- $v2w->init_inbox($shards, $skip_epoch, $skip_artnum);
+ importer($self)->init_inbox($shards, $skip_epoch);
}
}
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index b5ed7c02..b62d0477 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -76,7 +76,7 @@ sub new {
# public (for now?)
sub init_inbox {
- my ($self, $shards, $skip_epoch, $skip_artnum) = @_;
+ my ($self, $shards, $skip_epoch) = @_;
if (defined $shards) {
$self->{parallel} = 0 if $shards == 0;
$self->{shards} = $shards if $shards > 0;
@@ -85,6 +85,7 @@ sub init_inbox {
$max = $skip_epoch if (defined($skip_epoch) && !defined($max));
$self->{mg}->add_epoch($max // 0);
$self->idx_init;
+ my $skip_artnum = ($self->{ibx}->{-creat_opt} // {})->{'skip-artnum'};
$self->{mm}->skip_artnum($skip_artnum) if defined $skip_artnum;
$self->done;
}
diff --git a/script/public-inbox-init b/script/public-inbox-init
index cf6443f7..1e479a3a 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -34,15 +34,16 @@ EOF
require PublicInbox::Admin;
PublicInbox::Admin::require_or_die('-base');
-my ($version, $indexlevel, $skip_epoch, $skip_artnum, $jobs, $show_help);
+my ($version, $indexlevel, $skip_epoch, $jobs, $show_help);
my $skip_docdata;
my $ng = '';
my (@c_extra, @chdir);
+my $creat_opt = {};
my %opts = (
'V|version=i' => \$version,
'L|index-level|indexlevel=s' => \$indexlevel,
'S|skip|skip-epoch=i' => \$skip_epoch,
- 'skip-artnum=i' => \$skip_artnum,
+ 'skip-artnum=i' => \($creat_opt->{'skip-artnum'}),
'j|jobs=i' => \$jobs,
'ng|newsgroup=s' => \$ng,
'skip-docdata' => \$skip_docdata,
@@ -195,7 +196,6 @@ my $ibx = PublicInbox::Inbox->new({
indexlevel => $indexlevel,
});
-my $creat_opt = {};
if (defined $jobs) {
die "--jobs is only supported for -V2 inboxes\n" if $version == 1;
die "--jobs=$jobs must be >= 1\n" if $jobs <= 0;
@@ -210,7 +210,7 @@ if ($skip_docdata) {
die "--skip-docdata ignored with --indexlevel=basic\n";
$ibx->{-skip_docdata} = $skip_docdata;
}
-$ibx->init_inbox(0, $skip_epoch, $skip_artnum);
+$ibx->init_inbox(0, $skip_epoch);
my $f = "$inboxdir/description";
if (sysopen $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 05/14] init: move --skip-epoch handling to {-creat_opt}
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (3 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 04/14] init: move --skip-artnum handling to {-creat_opt} Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 06/14] lei_saved_search: drop needless comparisons and `next' Eric Wong
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
Epoch skipping only makes sense at inbox creation, thus we'll
bundle inbox creation options together to reduce potentionally
confusing positional parameters.
---
lib/PublicInbox/InboxWritable.pm | 4 ++--
lib/PublicInbox/V2Writable.pm | 3 ++-
script/public-inbox-init | 8 ++++----
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index a8239f49..f69aec75 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -50,13 +50,13 @@ sub _init_v1 {
}
sub init_inbox {
- my ($self, $shards, $skip_epoch) = @_;
+ my ($self, $shards) = @_;
if ($self->version == 1) {
my $dir = assert_usable_dir($self);
PublicInbox::Import::init_bare($dir);
$self->with_umask(\&_init_v1, $self);
} else {
- importer($self)->init_inbox($shards, $skip_epoch);
+ importer($self)->init_inbox($shards);
}
}
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index b62d0477..73c6dccc 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -76,12 +76,13 @@ sub new {
# public (for now?)
sub init_inbox {
- my ($self, $shards, $skip_epoch) = @_;
+ my ($self, $shards) = @_;
if (defined $shards) {
$self->{parallel} = 0 if $shards == 0;
$self->{shards} = $shards if $shards > 0;
}
my $max = $self->{ibx}->max_git_epoch;
+ my $skip_epoch = ($self->{ibx}->{-creat_opt} // {})->{'skip-epoch'};
$max = $skip_epoch if (defined($skip_epoch) && !defined($max));
$self->{mg}->add_epoch($max // 0);
$self->idx_init;
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 1e479a3a..b3f60bad 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -34,7 +34,7 @@ EOF
require PublicInbox::Admin;
PublicInbox::Admin::require_or_die('-base');
-my ($version, $indexlevel, $skip_epoch, $jobs, $show_help);
+my ($version, $indexlevel, $jobs, $show_help);
my $skip_docdata;
my $ng = '';
my (@c_extra, @chdir);
@@ -42,7 +42,7 @@ my $creat_opt = {};
my %opts = (
'V|version=i' => \$version,
'L|index-level|indexlevel=s' => \$indexlevel,
- 'S|skip|skip-epoch=i' => \$skip_epoch,
+ 'S|skip|skip-epoch=i' => \($creat_opt->{'skip-epoch'}),
'skip-artnum=i' => \($creat_opt->{'skip-artnum'}),
'j|jobs=i' => \$jobs,
'ng|newsgroup=s' => \$ng,
@@ -184,7 +184,7 @@ if (-f "$inboxdir/inbox.lock") {
$version = 1 unless defined $version;
-if ($version == 1 && defined $skip_epoch) {
+if ($version == 1 && defined $creat_opt->{'skip-epoch'}) {
die "--skip-epoch is only supported for -V2 inboxes\n";
}
@@ -210,7 +210,7 @@ if ($skip_docdata) {
die "--skip-docdata ignored with --indexlevel=basic\n";
$ibx->{-skip_docdata} = $skip_docdata;
}
-$ibx->init_inbox(0, $skip_epoch);
+$ibx->init_inbox(0);
my $f = "$inboxdir/description";
if (sysopen $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 06/14] lei_saved_search: drop needless comparisons and `next'
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (4 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 05/14] init: move --skip-epoch " Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 07/14] treewide: replace redundant `;;' with `;' Eric Wong
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
The grep(!/\A\.\.?\z/, ...) op already filters out the `.' and
`..' entries from `readdir'.
---
lib/PublicInbox/LeiSavedSearch.pm | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm
index 83e19357..0520ff98 100644
--- a/lib/PublicInbox/LeiSavedSearch.pm
+++ b/lib/PublicInbox/LeiSavedSearch.pm
@@ -85,7 +85,6 @@ sub list {
print $fh "[include]\n";
opendir(my $dh, $lss_dir);
for my $d (sort(grep(!/\A\.\.?\z/, readdir($dh)))) {
- next if $d eq '.' || $d eq '..';
my $p = "$lss_dir/$d/lei.saved-search";
say $fh "\tpath = ", cquote_val($p) if -f $p;
}
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 07/14] treewide: replace redundant `;;' with `;'
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (5 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 06/14] lei_saved_search: drop needless comparisons and `next' Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 08/14] lei_xsearch: use autodie for `pipe' ops Eric Wong
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
Wonky USB keyboard adapter or too much coffee sometimes makes me
type too many semi-colons (and other characters) :x
---
lib/PublicInbox/LeiSavedSearch.pm | 2 +-
t/lei-daemon.t | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm
index 0520ff98..612d1f43 100644
--- a/lib/PublicInbox/LeiSavedSearch.pm
+++ b/lib/PublicInbox/LeiSavedSearch.pm
@@ -91,7 +91,7 @@ sub list {
$fh->flush or die "flush: $fh";
my $cfg = $lei->cfg_dump($fh->filename);
my $out = $cfg ? $cfg->get_all('lei.q.output') : [];
- s!$LOCAL_PFX!! for @$out;;
+ s!$LOCAL_PFX!! for @$out;
@$out;
}
diff --git a/t/lei-daemon.t b/t/lei-daemon.t
index d97e494a..2422e6c5 100644
--- a/t/lei-daemon.t
+++ b/t/lei-daemon.t
@@ -48,7 +48,7 @@ test_lei({ daemon_only => 1 }, sub {
is($pid, $pid_again, 'pid unchanged after failed reqs');
my @after = sort(glob("$d/*"));
is_deeply(\@before, \@after, 'open files unchanged') or
- diag explain([\@before, \@after]);;
+ diag explain([\@before, \@after]);
}
lei_ok(qw(daemon-kill));
is($lei_out, '', 'no output from daemon-kill');
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 08/14] lei_xsearch: use autodie for `pipe' ops
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (6 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 07/14] treewide: replace redundant `;;' with `;' Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 09/14] treewide: use autodie for seek+sysseek Eric Wong
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
We already use autodie in this module and we can have more
consistent error messages this way.
---
lib/PublicInbox/LeiXSearch.pm | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index e20b13c6..b1f2fe5b 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -20,7 +20,7 @@ use PublicInbox::LEI;
use Fcntl qw(SEEK_SET F_SETFL O_APPEND O_RDWR);
use PublicInbox::ContentHash qw(git_sha);
use POSIX qw(strftime);
-use autodie qw(close open read seek truncate);
+use autodie qw(close open pipe read seek truncate);
use PublicInbox::Syscall qw($F_SETPIPE_SZ);
use PublicInbox::OnDestroy;
@@ -544,16 +544,16 @@ sub do_query {
$l2m->{base_type} =~ /\A(?:maildir|mbox)\z/) {
# setup two barriers to coordinate ->has_entries
# between l2m workers
- pipe(my ($a_r, $a_w)) or die "pipe: $!";
+ pipe my $a_r, my $a_w;
fcntl($a_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
- pipe(my ($b_r, $b_w)) or die "pipe: $!";
+ pipe my $b_r, my $b_w;
fcntl($b_r, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
$l2m->{au_peers} = [ $a_r, $a_w, $b_r, $b_w ];
}
$l2m->wq_workers_start('lei2mail', undef,
$lei->oldset, { lei => $lei },
\&xsearch_done_wait, $lei);
- pipe($lei->{startq}, $lei->{au_done}) or die "pipe: $!";
+ pipe $lei->{startq}, $lei->{au_done};
fcntl($lei->{startq}, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
delete $l2m->{au_peers};
close(delete $l2m->{-wq_s2}); # share wq_s1 with lei_xsearch
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 09/14] treewide: use autodie for seek+sysseek
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (7 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 08/14] lei_xsearch: use autodie for `pipe' ops Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 10/14] git: rely on autodie for sysseek/sysread/truncate Eric Wong
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
The underlying lseek(2) syscall won't fail due to HW errors,
only due to usage errors (ESPIPE, EINVAL); so don't waste
code on error checking ourselves and just let autodie check
things during development.
---
Documentation/common.perl | 3 ++-
lib/PublicInbox/Emergency.pm | 5 +++--
lib/PublicInbox/HTTP.pm | 5 +----
lib/PublicInbox/SolverGit.pm | 4 ++--
lib/PublicInbox/ViewVCS.pm | 9 ++++-----
lib/PublicInbox/WwwStatic.pm | 6 +++---
t/check-www-inbox.perl | 3 ++-
t/gcf2.t | 12 +++++++-----
t/gzip_filter.t | 2 +-
t/httpd-corner.t | 4 ++--
t/import.t | 3 ++-
t/ipc.t | 3 ++-
t/lei-externals.t | 5 +++--
t/lei-p2q.t | 5 +++--
t/lei-sigpipe.t | 4 ++--
t/mbox_reader.t | 6 +++---
16 files changed, 42 insertions(+), 37 deletions(-)
diff --git a/Documentation/common.perl b/Documentation/common.perl
index 53bae495..98a06ee1 100755
--- a/Documentation/common.perl
+++ b/Documentation/common.perl
@@ -2,6 +2,7 @@
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
+use autodie qw(seek);
use Fcntl qw(SEEK_SET);
use PublicInbox::Search;
my $addr = 'meta@public-inbox.org';
@@ -38,7 +39,7 @@ L<http://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/meta/>
my $t = time;
utime($t, $t, $fh);
} else {
- seek($fh, 0, SEEK_SET) or die "seek: $!";
+ seek $fh, 0, SEEK_SET;
truncate($fh, 0) or die "truncate: $!";
print $fh $s or die "print: $!";
close $fh or die "close: $!";
diff --git a/lib/PublicInbox/Emergency.pm b/lib/PublicInbox/Emergency.pm
index 968d7d6f..d3a83408 100644
--- a/lib/PublicInbox/Emergency.pm
+++ b/lib/PublicInbox/Emergency.pm
@@ -9,6 +9,7 @@ use Sys::Hostname qw(hostname);
use IO::Handle; # ->flush
use Errno qw(EEXIST);
use File::Path ();
+use autodie qw(seek sysseek);
sub new {
my ($class, $dir) = @_;
@@ -57,8 +58,8 @@ sub abort {
sub fh {
my ($self) = @_;
my $fh = $self->{fh} or die "BUG: {fh} not open";
- seek($fh, 0, SEEK_SET) or die "seek: $!";
- sysseek($fh, 0, SEEK_SET) or die "sysseek: $!";
+ seek $fh, 0, SEEK_SET;
+ sysseek $fh, 0, SEEK_SET;
$fh;
}
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 88cab544..80ebad16 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -147,10 +147,7 @@ sub app_dispatch {
$host =~ s/:([0-9]+)\z// and $env->{SERVER_PORT} = $1 + 0;
$env->{SERVER_NAME} = $host;
}
- if (defined $input) {
- sysseek($input, 0, SEEK_SET) or
- die "BUG: psgi.input seek failed: $!";
- }
+ sysseek($input, 0, SEEK_SET) if defined $input;
# note: NOT $self->{sock}, we want our close (+ PublicInbox::DS::close),
# to do proper cleanup:
$env->{'psgix.io'} = $self; # for ->close or async_pass
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index d9465771..e30761e2 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -11,7 +11,7 @@ package PublicInbox::SolverGit;
use strict;
use v5.10.1;
use File::Temp 0.19 (); # 0.19 for ->newdir
-use autodie qw(mkdir);
+use autodie qw(mkdir sysseek);
use Fcntl qw(SEEK_SET);
use PublicInbox::Git qw(git_unquote git_quote git_exe);
use PublicInbox::IO qw(write_file);
@@ -342,7 +342,7 @@ sub prepare_index ($) {
my $in = tmpfile("update-index.$oid_full") or die "tmpfile: $!";
print $in "$mode_a $oid_full\t$path_a\0" or die "print: $!";
$in->flush or die "flush: $!";
- sysseek($in, 0, SEEK_SET) or die "seek: $!";
+ sysseek $in, 0, SEEK_SET;
dbg($self, 'preparing index');
my $rdr = { 0 => $in };
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index d9df671c..8d937cff 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -65,11 +65,10 @@ sub html_page ($$;@) {
sub dbg_log ($) {
my ($ctx) = @_;
my $log = delete $ctx->{lh} // die 'BUG: already captured debug log';
- if (!CORE::seek($log, 0, SEEK_SET)) {
- warn "seek(log): $!";
- return '<pre>debug log seek error</pre>';
- }
- $log = eval { PublicInbox::IO::read_all $log } // do {
+ $log = eval {
+ seek $log, 0, SEEK_SET;
+ PublicInbox::IO::read_all $log;
+ } // do {
warn "read(log): $@";
return '<pre>debug log read error</pre>';
};
diff --git a/lib/PublicInbox/WwwStatic.pm b/lib/PublicInbox/WwwStatic.pm
index d8902193..af4eb960 100644
--- a/lib/PublicInbox/WwwStatic.pm
+++ b/lib/PublicInbox/WwwStatic.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-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>
# This package can either be a PSGI response body for a static file
@@ -11,6 +11,7 @@ package PublicInbox::WwwStatic;
use strict;
use v5.10.1;
use parent qw(Exporter);
+use autodie qw(sysseek);
use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
use HTTP::Date qw(time2str);
use HTTP::Status qw(status_message);
@@ -178,8 +179,7 @@ sub getline {
my $len = $self->{len} or return; # undef, tells server we're done
my $n = 8192;
$n = $len if $len < $n;
- sysseek($self->{in}, $self->{off}, SEEK_SET) or
- die "sysseek ($self->{path}): $!";
+ sysseek $self->{in}, $self->{off}, SEEK_SET;
my $r = sysread($self->{in}, my $buf, $n);
if (defined $r && $r > 0) { # success!
$self->{len} = $len - $r;
diff --git a/t/check-www-inbox.perl b/t/check-www-inbox.perl
index 46f9ce1e..1b9db49e 100644
--- a/t/check-www-inbox.perl
+++ b/t/check-www-inbox.perl
@@ -4,7 +4,8 @@
# Parallel WWW checker
my $usage = "$0 [-j JOBS] [-s SLOW_THRESHOLD] URL_OF_INBOX\n";
use strict;
-use warnings;
+use v5.10.1;
+use autodie qw(sysseek);
use File::Temp qw(tempfile);
use GDBM_File;
use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
diff --git a/t/gcf2.t b/t/gcf2.t
index 33f3bbca..9f9e8e20 100644
--- a/t/gcf2.t
+++ b/t/gcf2.t
@@ -1,7 +1,9 @@
#!perl -w
-# Copyright (C) 2020-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>
use strict;
+use v5.10.1;
+use autodie qw(seek);
use PublicInbox::TestCommon;
use Test::More;
use Fcntl qw(:seek);
@@ -80,18 +82,18 @@ SKIP: {
$fh->autoflush(1);
ok(!$gcf2->cat_oid(fileno($fh), 'invalid'), 'invalid fails');
- seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+ seek $fh, 0, SEEK_SET;
is(do { local $/; <$fh> }, '', 'nothing written');
open $fh, '+>', undef or BAIL_OUT "open: $!";
ok(!$gcf2->cat_oid(fileno($fh), '0'x40), 'z40 fails');
- seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+ seek $fh, 0, SEEK_SET;
is(do { local $/; <$fh> }, '', 'nothing written for z40');
open $fh, '+>', undef or BAIL_OUT "open: $!";
my $ck_copying = sub {
my ($desc) = @_;
- seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+ seek $fh, 0, SEEK_SET;
is(<$fh>, "$COPYING blob 34520\n", "got expected header $desc");
my $buf = do { local $/; <$fh> };
is(chop($buf), "\n", 'got trailing \\n');
@@ -113,7 +115,7 @@ SKIP: {
fcntl($w, $F_SETPIPE_SZ, 4096) or
skip('Linux too old for F_SETPIPE_SZ', 14);
$w->blocking($blk);
- seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+ seek $fh, 0, SEEK_SET;
truncate($fh, 0) or BAIL_OUT "truncate: $!";
my $pid = fork // BAIL_OUT "fork: $!";
if ($pid == 0) {
diff --git a/t/gzip_filter.t b/t/gzip_filter.t
index 97eac2d0..f827510f 100644
--- a/t/gzip_filter.t
+++ b/t/gzip_filter.t
@@ -16,7 +16,7 @@ require_ok 'PublicInbox::GzipFilter';
ok($filter->write("hello"), 'wrote something');
ok($filter->write("world"), 'wrote more');
$filter->close;
- seek($fh, 0, SEEK_SET) or die;
+ seek $fh, 0, SEEK_SET;
IO::Uncompress::Gunzip::gunzip($fh => \(my $buf));
is($buf, 'helloworld', 'buffer matches');
}
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index 125610d6..e653f1e1 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -5,7 +5,7 @@
# generic PSGI/Plack apps.
use v5.12; use PublicInbox::TestCommon;
use Time::HiRes qw(gettimeofday tv_interval);
-use autodie qw(getsockopt setsockopt);
+use autodie qw(getsockopt seek setsockopt);
use PublicInbox::Spawn qw(spawn popen_rd);
require_mods '-httpd';
use PublicInbox::SHA qw(sha1_hex);
@@ -676,7 +676,7 @@ SKIP: {
$req = GET('http://example.com/psgi-yield-enoent');
$res = $cb->($req);
is($res->code, 500, 'got error on ENOENT');
- seek($tmperr, 0, SEEK_SET) or die;
+ seek $tmperr, 0, SEEK_SET;
my $errbuf = do { local $/; <$tmperr> };
like($errbuf, qr/this-better-not-exist/,
'error logged about missing command');
diff --git a/t/import.t b/t/import.t
index 7e2432e7..48416eb2 100644
--- a/t/import.t
+++ b/t/import.t
@@ -3,6 +3,7 @@
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use v5.10.1;
use strict;
+use autodie qw(seek);
use PublicInbox::Eml;
use PublicInbox::Smsg;
use PublicInbox::Git;
@@ -36,7 +37,7 @@ SKIP: {
open my $in, '+<', undef or BAIL_OUT "open(+<): $!";
print $in $mime->as_string or die "write failed: $!";
$in->flush or die "flush failed: $!";
- seek($in, 0, SEEK_SET) or die "seek: $!";
+ seek $in, 0, SEEK_SET;
chomp(my $hashed_obj = xqx(\@cmd, undef, { 0 => $in }));
is($?, 0, 'hash-object');
is($hashed_obj, $smsg->{blob}, "blob object_id matches exp");
diff --git a/t/ipc.t b/t/ipc.t
index 23ae2e7b..fc6f96a2 100644
--- a/t/ipc.t
+++ b/t/ipc.t
@@ -2,6 +2,7 @@
# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use v5.12;
+use autodie qw(seek);
use PublicInbox::TestCommon;
use Fcntl qw(SEEK_SET);
use PublicInbox::SHA qw(sha1_hex);
@@ -176,7 +177,7 @@ SKIP: {
$ipc->wq_close;
SKIP: {
skip 'Socket::MsgHdr or Inline::C missing', 11 if !$ppids[0];
- seek($warn, 0, SEEK_SET) or BAIL_OUT;
+ seek $warn, 0, SEEK_SET;
my @warn = <$warn>;
is(scalar(@warn), 2, 'warned 3 times');
like($warn[0], qr/ wq_worker: /, '2nd warned from wq_worker');
diff --git a/t/lei-externals.t b/t/lei-externals.t
index 4f2dd6ba..32e1255b 100644
--- a/t/lei-externals.t
+++ b/t/lei-externals.t
@@ -1,8 +1,9 @@
#!perl -w
-# Copyright (C) 2020-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>
use strict; use v5.10.1; use PublicInbox::TestCommon;
use Fcntl qw(SEEK_SET);
+use autodie qw(seek);
require_git 2.6;
require_mods(qw(json DBD::SQLite Xapian));
use POSIX qw(WTERMSIG WIFSIGNALED SIGPIPE);
@@ -200,7 +201,7 @@ test_lei(sub {
open my $fh, '+>', undef or BAIL_OUT $!;
$fh->autoflush(1);
print $fh 's:use d:..5.days.from.now' or BAIL_OUT $!;
- seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
+ seek $fh, 0, SEEK_SET;
lei_ok([qw(q -q --stdin)], undef, { %$lei_opt, 0 => $fh },
\'--stdin on regular file works');
like($lei_out, qr/use boolean/, '--stdin on regular file');
diff --git a/t/lei-p2q.t b/t/lei-p2q.t
index 44f37d19..778aa68f 100644
--- a/t/lei-p2q.t
+++ b/t/lei-p2q.t
@@ -1,7 +1,8 @@
#!perl -w
-# 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>
use strict; use v5.10.1; use PublicInbox::TestCommon;
+use autodie qw(sysseek);
require_git 2.6;
require_mods(qw(json DBD::SQLite Xapian));
@@ -15,7 +16,7 @@ test_lei(sub {
lei_ok([qw(p2q -w dfpost -)], undef, { %$lei_opt, 0 => $fh });
is($lei_out, "dfpost:6e006fd73b1d\n", '--stdin') or diag $lei_err;
- sysseek($fh, 0, 0) or xbail "lseek: $!";
+ sysseek $fh, 0, 0;
lei_ok([qw(p2q -w dfpost)], undef, { %$lei_opt, 0 => $fh });
is($lei_out, "dfpost:6e006fd73b1d\n", 'implicit --stdin');
diff --git a/t/lei-sigpipe.t b/t/lei-sigpipe.t
index c01d9f83..db4f9288 100644
--- a/t/lei-sigpipe.t
+++ b/t/lei-sigpipe.t
@@ -55,7 +55,7 @@ EOM
close $w;
vec(my $rvec = '', fileno($r), 1) = 1;
if (!select($rvec, undef, undef, 30)) {
- seek($errfh, 0, 0);
+ seek $errfh, 0, 0;
my $s = do { local $/; <$errfh> };
xbail "lei q had no output after 30s, stderr=$s";
}
@@ -64,7 +64,7 @@ EOM
$tp->join;
ok(WIFSIGNALED($?), "signaled @$out");
is(WTERMSIG($?), SIGPIPE, "got SIGPIPE @$out");
- seek($errfh, 0, 0);
+ seek $errfh, 0, 0;
my $s = do { local $/; <$errfh> };
is($s, '', "quiet after sigpipe @$out");
}
diff --git a/t/mbox_reader.t b/t/mbox_reader.t
index 14248a2d..1fa9068e 100644
--- a/t/mbox_reader.t
+++ b/t/mbox_reader.t
@@ -1,9 +1,9 @@
#!perl -w
-# Copyright (C) 2020-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>
use strict;
use v5.10.1;
-use Test::More;
+use autodie qw(seek);
use PublicInbox::TestCommon;
use List::Util qw(shuffle);
use PublicInbox::Eml;
@@ -52,7 +52,7 @@ my $check_fmt = sub {
my $buf = $eml2mbox->($eml);
print $fh $$buf or BAIL_OUT "print $!";
}
- seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
+ seek $fh, 0, SEEK_SET;
$reader->$fmt($fh, sub {
my ($eml) = @_;
$eml->header_set('Status');
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 10/14] git: rely on autodie for sysseek/sysread/truncate
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (8 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 09/14] treewide: use autodie for seek+sysseek Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 11/14] config: config_fh_parse: hardcode FS/RS Eric Wong
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
Error messages are more consistent with autodie. We'll also
drop autodie::read since it's no longer in use for this package.
---
lib/PublicInbox/Git.pm | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index b3f39adf..9e0840ab 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -11,8 +11,8 @@ use strict;
use v5.10.1;
use parent qw(Exporter PublicInbox::DS);
use PublicInbox::DS qw(now);
-use autodie qw(socketpair read);
-use POSIX ();
+use autodie qw(socketpair sysread sysseek truncate);
+use POSIX qw(SEEK_SET);
use Socket qw(AF_UNIX SOCK_STREAM);
use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
use Errno qw(EAGAIN);
@@ -145,11 +145,13 @@ sub object_format {
sub last_check_err {
my ($self) = @_;
my $fh = $self->{err_c} or return '';
- sysseek($fh, 0, 0) or $self->fail("sysseek: $!");
my $size = -s $fh or return '';
- sysread($fh, my $buf, $size) // $self->fail("sysread: $!");
- truncate($fh, 0) or $self->fail("truncate: $!");
- $buf;
+ eval {
+ sysseek $fh, 0, SEEK_SET;
+ sysread($fh, my $buf, $size);
+ truncate $fh, 0;
+ $buf;
+ } // $self->fail($@);
}
sub gcf_drain { # awaitpid cb
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 11/14] config: config_fh_parse: hardcode FS/RS
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (9 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 10/14] git: rely on autodie for sysseek/sysread/truncate Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 12/14] v2writable: remove outdated FIXME comment and assertions Eric Wong
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
We no longer need the flexibility to handle non-NUL-delimited
output from `git config -l', so simplify callers and allow
a theoretically sufficiently-advanced Perl implementation
optimize more easily.
Followup-to: 21146412 (config: drop scalar ref support from internal API, 2023-09-24)
---
lib/PublicInbox/Config.pm | 14 +++++++-------
lib/PublicInbox/LeiViewText.pm | 3 ++-
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 358ddd2a..03db2a51 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -139,15 +139,15 @@ sub default_file {
$ENV{PI_CONFIG} // (config_dir() . '/config');
}
-sub config_fh_parse ($$$) {
- my ($fh, $rs, $fs) = @_;
+sub config_fh_parse ($) {
+ my ($fh) = @_;
my (%rv, %seen, @section_order, $line, $k, $v, $section, $cur, $i);
- local $/ = $rs;
+ local $/ = "\0";
while (defined($line = <$fh>)) { # perf critical with giant configs
- $i = index($line, $fs);
- # $i may be -1 if $fs not found and it's a key-only entry
+ $i = index($line, "\n");
+ # $i may be -1 if "\n" isn't found and it's a key-only entry
# (meaning boolean true). Either way the -1 will drop the
- # $rs either from $k or $v.
+ # "\n" either from $k or $v.
$k = substr($line, 0, $i);
$v = $i >= 0 ? substr($line, $i + 1, -1) : 1;
$section = substr($k, 0, rindex($k, '.'));
@@ -195,7 +195,7 @@ sub git_config_dump {
my @cmd = (git_exe, @opt_c, qw(config -z -l --includes));
push(@cmd, '-f', $file) if !@opt_c && defined($file);
my $fh = popen_rd(\@cmd, \%env, $opt);
- my $rv = config_fh_parse($fh, "\0", "\n");
+ my $rv = config_fh_parse $fh;
$fh->close or die "@cmd failed: \$?=$?\n";
$rv->{-opt_c} = \@opt_c if @opt_c; # for ->urlmatch
$rv->{-f} = $file;
diff --git a/lib/PublicInbox/LeiViewText.pm b/lib/PublicInbox/LeiViewText.pm
index fa608ca2..9ab01ffb 100644
--- a/lib/PublicInbox/LeiViewText.pm
+++ b/lib/PublicInbox/LeiViewText.pm
@@ -8,6 +8,7 @@ use strict;
use v5.10.1;
use PublicInbox::MsgIter qw(msg_part_text);
use PublicInbox::MID qw(references);
+use PublicInbox::Config;
use PublicInbox::View;
use PublicInbox::Hval;
use PublicInbox::ViewDiff;
@@ -75,7 +76,7 @@ sub new {
return $self unless $self->{color} //= -t $lei->{1};
my @cmd = (git_exe, qw(config -z --includes -l)); # reuse normal git cfg
my $r = popen_rd(\@cmd, undef, { 2 => $lei->{2} });
- my $cfg = PublicInbox::Config::config_fh_parse($r, "\0", "\n");
+ my $cfg = PublicInbox::Config::config_fh_parse $r;
if (!$r->close) {
warn "# @cmd failed, no color (non-fatal \$?=$?)\n";
return $self;
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 12/14] v2writable: remove outdated FIXME comment and assertions
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (10 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 11/14] config: config_fh_parse: hardcode FS/RS Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 13/14] mda: use read_all for error handling Eric Wong
2025-01-18 1:26 ` [PATCH 14/14] emergency: remove needless $! clobber Eric Wong
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
The lei/store bug was resolved and thus the comments and
assertions are no longer necessary.
Followup-to: 99fc3d76 (v2writable: done: force synchronous awaitpid, 2024-11-19)
---
lib/PublicInbox/V2Writable.pm | 3 ---
1 file changed, 3 deletions(-)
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 73c6dccc..3ae6c4d0 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -93,9 +93,6 @@ sub init_inbox {
sub idx_shard ($$) {
my ($self, $num) = @_;
- # FIXME: lei_store bug somewhere..
- confess 'BUG: {idx_shards} unset' if !$self->{idx_shards};
- confess 'BUG: {idx_shards} empty' if !@{$self->{idx_shards}};
$self->{idx_shards}->[$num % scalar(@{$self->{idx_shards}})];
}
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 13/14] mda: use read_all for error handling
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (11 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 12/14] v2writable: remove outdated FIXME comment and assertions Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
2025-01-18 1:26 ` [PATCH 14/14] emergency: remove needless $! clobber Eric Wong
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
We already imported PublicInbox::IO for this script and read_all
provides more safety in case default PerlIO semantics change for
read-in-full behavior.
---
script/public-inbox-mda | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/script/public-inbox-mda b/script/public-inbox-mda
index 9d68ea35..bc1dc286 100755
--- a/script/public-inbox-mda
+++ b/script/public-inbox-mda
@@ -100,8 +100,7 @@ if ($spamc) {
} else { # no spam checking configured:
$spam_ok = 1;
$emm = $ems;
- my $fh = $emm->fh;
- read($fh, $str, -s $fh);
+ PublicInbox::IO::read_all $emm->fh, undef, \$str;
}
$do_exit->(0) unless $spam_ok;
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 14/14] emergency: remove needless $! clobber
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
` (12 preceding siblings ...)
2025-01-18 1:26 ` [PATCH 13/14] mda: use read_all for error handling Eric Wong
@ 2025-01-18 1:26 ` Eric Wong
13 siblings, 0 replies; 15+ messages in thread
From: Eric Wong @ 2025-01-18 1:26 UTC (permalink / raw)
To: meta
We don't check $! unless `sysopen' fails, and `sysopen' will set
$! on failure so there's no need to undef $! ourselves.
---
lib/PublicInbox/Emergency.pm | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/PublicInbox/Emergency.pm b/lib/PublicInbox/Emergency.pm
index d3a83408..7e9faad0 100644
--- a/lib/PublicInbox/Emergency.pm
+++ b/lib/PublicInbox/Emergency.pm
@@ -39,7 +39,6 @@ sub prepare {
my ($tmp, $fh);
do {
$tmp = _fn_in($self, $pid, 'tmp');
- $! = undef;
} while (!sysopen($fh, $tmp, O_CREAT|O_EXCL|O_RDWR) and $! == EEXIST);
print $fh $$strref or die "print: $!";
$fh->flush or die "flush: $!";
^ permalink raw reply related [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-01-18 1:26 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-18 1:26 [PATCH 00/14] various odds and ends Eric Wong
2025-01-18 1:26 ` [PATCH 01/14] inbox_writable: use autodie::open Eric Wong
2025-01-18 1:26 ` [PATCH 02/14] v2writable: simplify ->new by reducing arg flexibility Eric Wong
2025-01-18 1:26 ` [PATCH 03/14] inbox_writable: match v1 and v2 init semantics Eric Wong
2025-01-18 1:26 ` [PATCH 04/14] init: move --skip-artnum handling to {-creat_opt} Eric Wong
2025-01-18 1:26 ` [PATCH 05/14] init: move --skip-epoch " Eric Wong
2025-01-18 1:26 ` [PATCH 06/14] lei_saved_search: drop needless comparisons and `next' Eric Wong
2025-01-18 1:26 ` [PATCH 07/14] treewide: replace redundant `;;' with `;' Eric Wong
2025-01-18 1:26 ` [PATCH 08/14] lei_xsearch: use autodie for `pipe' ops Eric Wong
2025-01-18 1:26 ` [PATCH 09/14] treewide: use autodie for seek+sysseek Eric Wong
2025-01-18 1:26 ` [PATCH 10/14] git: rely on autodie for sysseek/sysread/truncate Eric Wong
2025-01-18 1:26 ` [PATCH 11/14] config: config_fh_parse: hardcode FS/RS Eric Wong
2025-01-18 1:26 ` [PATCH 12/14] v2writable: remove outdated FIXME comment and assertions Eric Wong
2025-01-18 1:26 ` [PATCH 13/14] mda: use read_all for error handling Eric Wong
2025-01-18 1:26 ` [PATCH 14/14] emergency: remove needless $! clobber Eric Wong
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).