* [PATCH 00/14] Alpine Linux support
@ 2023-12-13 0:50 7% Eric Wong
2023-12-13 0:50 6% ` [PATCH 06/14] treewide: avoid strftime %k for portability Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-12-13 0:50 UTC (permalink / raw)
To: meta
I haven't tested every single possible package combination, but
I think this is enough to get started.
Patch 3 was a WTF moment for me.
Some of these are relevant for other platforms, as well, and
patch 7 decoupling from Inline::C is a good step towards making
our codebase more modular.
Patch 12 is a good fix regardless.
Eric Wong (14):
t/io: strace is optional on Linux
tests: account for missing git-http-backend
t/cindex*: skip --join when join(1) is missing
tests: attempt compatibility w/ busybox lsof
lei inspect: drop unneeded strftime import
treewide: avoid strftime %k for portability
xap_helper_cxx: decouple from Inline::C
xap_helper_cxx: support clang w/o `c++' executable
install: updates for Alpine Linux and apk
test_common: extract oct_is from search.t
t/convert-compact: allow S_ISGID bit
www_coderepo: fix read buffering
gzip_filter: use OO ->zflush dispatch
t/lei-import: relax EIO regexp
install/deps.perl | 38 +++++++++++++++++++++----
install/os.perl | 12 ++++++--
lib/PublicInbox/Admin.pm | 10 ++++++-
lib/PublicInbox/ExtSearchIdx.pm | 4 +--
lib/PublicInbox/GzipFilter.pm | 2 +-
lib/PublicInbox/Hval.pm | 6 +++-
lib/PublicInbox/LeiInspect.pm | 1 -
lib/PublicInbox/LeiMirror.pm | 4 +--
lib/PublicInbox/LeiXSearch.pm | 3 +-
lib/PublicInbox/RepoAtom.pm | 4 +--
lib/PublicInbox/TestCommon.pm | 50 +++++++++++++++++++++++++++++++--
lib/PublicInbox/WwwCoderepo.pm | 6 ++--
lib/PublicInbox/WwwStatic.pm | 5 ++--
lib/PublicInbox/XapHelperCxx.pm | 26 +++++++++++------
t/cindex-join.t | 1 +
t/cindex.t | 11 ++++----
t/clone-coderepo.t | 1 +
t/convert-compact.t | 20 ++++++-------
t/ds-leak.t | 5 +---
t/httpd-corner.t | 31 ++++++++------------
t/httpd.t | 1 +
t/lei-import.t | 5 ++--
t/lei-mirror.t | 1 +
t/nntpd.t | 16 +++++------
t/search.t | 5 ----
t/solver_git.t | 8 ++++--
t/v2reindex.t | 5 ++--
t/www_listing.t | 1 +
t/xap_helper.t | 6 ++--
xt/msgtime_cmp.t | 2 +-
30 files changed, 190 insertions(+), 100 deletions(-)
^ permalink raw reply [relevance 7%]
* [PATCH 06/14] treewide: avoid strftime %k for portability
2023-12-13 0:50 7% [PATCH 00/14] Alpine Linux support Eric Wong
@ 2023-12-13 0:50 6% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-12-13 0:50 UTC (permalink / raw)
To: meta
The musl strftime(3) implementation on AlpineLinux 3.19.0
doesn't support `%k' and `%k' isn't in POSIX, either. So we
fall back to using the `sprintf' perlop in the user-facing UI
since leading zeroes require needless overhead for my eyes and
brain to parse in the time.
---
lib/PublicInbox/Admin.pm | 10 +++++++++-
lib/PublicInbox/ExtSearchIdx.pm | 4 ++--
lib/PublicInbox/Hval.pm | 6 +++++-
lib/PublicInbox/LeiMirror.pm | 4 ++--
lib/PublicInbox/LeiXSearch.pm | 3 ++-
lib/PublicInbox/WwwStatic.pm | 5 ++---
xt/msgtime_cmp.t | 2 +-
7 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm
index cc9d2171..a1b1fc07 100644
--- a/lib/PublicInbox/Admin.pm
+++ b/lib/PublicInbox/Admin.pm
@@ -6,7 +6,7 @@
package PublicInbox::Admin;
use v5.12;
use parent qw(Exporter);
-our @EXPORT_OK = qw(setup_signals);
+our @EXPORT_OK = qw(setup_signals fmt_localtime);
use PublicInbox::Config;
use PublicInbox::Inbox;
use PublicInbox::Spawn qw(run_qx);
@@ -381,4 +381,12 @@ sub do_chdir ($) {
}
}
+sub fmt_localtime ($) {
+ require POSIX;
+ my @lt = localtime $_[0];
+ my (undef, $M, $H, $d, $m, $Y) = @lt;
+ sprintf('%u-%02u-%02u % 2u:%02u ', $Y + 1900, $m + 1, $d, $H, $M)
+ .POSIX::strftime('%z', @lt);
+}
+
1;
diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index 7b7436ea..53078124 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -20,7 +20,6 @@ use parent qw(PublicInbox::ExtSearch PublicInbox::Umask PublicInbox::Lock);
use Carp qw(croak carp);
use Scalar::Util qw(blessed);
use Sys::Hostname qw(hostname);
-use POSIX qw(strftime);
use File::Glob qw(bsd_glob GLOB_NOSORT);
use PublicInbox::MultiGit;
use PublicInbox::Search;
@@ -34,6 +33,7 @@ use PublicInbox::ContentHash qw(content_hash);
use PublicInbox::Eml;
use PublicInbox::DS qw(now add_timer);
use DBI qw(:sql_types); # SQL_BLOB
+use PublicInbox::Admin qw(fmt_localtime);
sub new {
my (undef, $dir, $opt) = @_;
@@ -749,7 +749,7 @@ sub eidxq_lock_acquire ($) {
return $locked if $locked eq $cur;
}
my ($pid, $time, $euid, $ident) = split(/-/, $cur, 4);
- my $t = strftime('%Y-%m-%d %k:%M %z', localtime($time));
+ my $t = fmt_localtime($time);
local $self->{current_info} = 'eidxq';
if ($euid == $> && $ident eq host_ident) {
kill(0, $pid) and warn <<EOM and return;
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index b804254a..963dbb71 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -145,7 +145,11 @@ sub to_attr ($) {
sub ts2str ($) { strftime('%Y%m%d%H%M%S', gmtime($_[0])) };
# human-friendly format
-sub fmt_ts ($) { strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
+sub fmt_ts ($) {
+ # strftime %k is not portable and leading zeros in %H slow me down
+ my (undef, $M, $H, $d, $m, $Y) = gmtime $_[0];
+ sprintf '%u-%02u-%02u % 2u:%02u', $Y + 1900, $m + 1, $d, $H, $M;
+}
sub utf8_maybe ($) {
utf8::decode($_[0]);
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index e048a807..0c77a8b5 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -21,6 +21,7 @@ use PublicInbox::LeiCurl;
use PublicInbox::OnDestroy;
use PublicInbox::SHA qw(sha256_hex sha_all);
use POSIX qw(strftime);
+use PublicInbox::Admin qw(fmt_localtime);
use autodie qw(chdir chmod close open pipe readlink
seek symlink sysopen sysseek truncate unlink);
@@ -1232,8 +1233,7 @@ EOM
# set by clone_v2_prep/-I/--exclude
my $mis = delete $self->{chg}->{fp_mismatch};
if ($mis) {
- my $t = (stat($ft))[9];
- $t = strftime('%F %k:%M:%S %z', localtime($t));
+ my $t = fmt_localtime((stat($ft))[9]);
warn <<EOM;
W: Fingerprints for the following repositories do not match
W: $mf_url @ $t:
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index cee3ad07..fc95d401 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -298,8 +298,9 @@ sub fudge_qstr_time ($$$) {
$rft = $diff;
}
$lr -= ($rft || (48 * 60 * 60));
+ require PublicInbox::Admin;
$lei->qerr("# $uri limiting to ".
- strftime('%Y-%m-%d %k:%M %z', localtime($lr)). ' and newer');
+ PublicInbox::Admin::fmt_localtime($lr).' and newer');
# this should really be rt: (received-time), but no stable
# public-inbox releases support it, yet.
my $dt = 'dt:'.strftime('%Y%m%d%H%M%S', gmtime($lr)).'..';
diff --git a/lib/PublicInbox/WwwStatic.pm b/lib/PublicInbox/WwwStatic.pm
index 1c1a3d38..d8902193 100644
--- a/lib/PublicInbox/WwwStatic.pm
+++ b/lib/PublicInbox/WwwStatic.pm
@@ -12,13 +12,12 @@ use strict;
use v5.10.1;
use parent qw(Exporter);
use Fcntl qw(SEEK_SET O_RDONLY O_NONBLOCK);
-use POSIX qw(strftime);
use HTTP::Date qw(time2str);
use HTTP::Status qw(status_message);
use Errno qw(EACCES ENOTDIR ENOENT);
use URI::Escape qw(uri_escape_utf8);
use PublicInbox::GzipFilter qw(gzf_maybe);
-use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::Hval qw(ascii_html fmt_ts);
use Plack::MIME;
our @EXPORT_OK = qw(@NO_CACHE r path_info_raw);
@@ -299,7 +298,7 @@ sub dir_response ($$$) {
$pad = 1 if $pad <= 0;
$entry = qq(\n<a\nhref="$href">$name</a>) .
(' ' x $pad) .
- strftime('%Y-%m-%d %k:%M', gmtime($mtime)) .
+ fmt_ts($mtime) .
sprintf('% 8s', $hsize);
}
diff --git a/xt/msgtime_cmp.t b/xt/msgtime_cmp.t
index a7ef5245..c63f785e 100644
--- a/xt/msgtime_cmp.t
+++ b/xt/msgtime_cmp.t
@@ -36,7 +36,7 @@ sub quiet_is_deeply ($$$$$) {
($old->[0] != $cur->[0]) ||
($old->[1] != $cur->[1]))) {
for ($cur, $old) {
- $_->[2] = strftime('%Y-%m-%d %k:%M:%S', gmtime($_->[0]))
+ $_->[2] = strftime('%F %T', gmtime($_->[0]))
}
is_deeply($cur, $old, "$func $oid");
diag('got: ', explain($cur));
^ permalink raw reply related [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-12-13 0:50 7% [PATCH 00/14] Alpine Linux support Eric Wong
2023-12-13 0:50 6% ` [PATCH 06/14] treewide: avoid strftime %k for portability 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).