]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www_coderepo: fix read buffering
authorEric Wong <e@80x24.org>
Wed, 13 Dec 2023 00:50:17 +0000 (00:50 +0000)
committerEric Wong <e@80x24.org>
Wed, 13 Dec 2023 09:01:54 +0000 (09:01 +0000)
Our read buffering only worked well with the stdout buffering on
glibc and *BSD libc, but not musl.  When reading the stdout of
git(1), we are likely to get smaller buffers and require more
reads on musl-based systems (tested Alpine Linux 3.19.0).

Thus we must prevent ->translate from being called with an empty
argument list (denoting EOF).  We'll also avoid some local
variable assignments while at it and favor the non-OO ->zflush
dispatch inside RepoAtom and WwwCoderepo subclasses.

lib/PublicInbox/RepoAtom.pm
lib/PublicInbox/WwwCoderepo.pm
t/solver_git.t

index c1649d0a7b32e8cc2ac8ee60f14cf638f0aa3c9a..ab0f2fcc647d778f1c89206df7f928d50bacbfd1 100644 (file)
@@ -43,7 +43,7 @@ sub zflush { $_[0]->SUPER::zflush('</feed>') }
 # called by GzipFilter->write or GetlineResponse->getline
 sub translate {
        my $self = shift;
-       my $rec = $_[0] // return $self->zflush; # getline
+       $_[0] // return zflush($self); # getline caller
        my @out;
        my $lbuf = delete($self->{lbuf}) // shift;
        $lbuf .= shift while @_;
@@ -87,7 +87,7 @@ xmlns="http://www.w3.org/1999/xhtml"><pre style="white-space:pre-wrap">
        }
        $self->{lbuf} = $lbuf;
        chomp @out;
-       $self->SUPER::translate(@out);
+       @out ? $self->SUPER::translate(@out) : ''; # not EOF, yet
 }
 
 # $REPO/tags.atom endpoint
index d1354af558e3ce81a1defb687403ceb944d414ae..3814f71970792267e80238e36c032185b0d9b27e 100644 (file)
@@ -273,7 +273,7 @@ sub zflush { $_[0]->SUPER::zflush('</pre>', $_[0]->_html_end) }
 # called by GzipFilter->write or GetlineResponse->getline
 sub translate {
        my $ctx = shift;
-       my $rec = $_[0] // return zflush($ctx); # getline
+       $_[0] // return zflush($ctx); # getline caller
        my @out;
        my $fbuf = delete($ctx->{fbuf}) // shift;
        $fbuf .= shift while @_;
@@ -290,8 +290,8 @@ sub translate {
                                                $snap_pfx, @snap_fmt);
                }
        }
-       $ctx->{fbuf} = $fbuf;
-       $ctx->SUPER::translate(@out);
+       $ctx->{fbuf} = $fbuf; # may be incomplete
+       @out ? $ctx->SUPER::translate(@out) : ''; # not EOF, yet
 }
 
 sub _refs_parse_hdr { # {parse_hdr} for Qspawn
index ab8aba15dba5fa088e086f3c63deab85c8f2fcdf..db6729040c96eb19b8d274ca4d10c0949e6059d9 100644 (file)
@@ -405,14 +405,16 @@ EOF
                is($res->code, 200, 'Atom feed');
                SKIP: {
                        require_mods('XML::TreePP', 1);
-                       my $t = XML::TreePP->new->parse($res->content);
+                       my $t = eval { XML::TreePP->new->parse($res->content) }
+                               or diag explain($res);
                        is(scalar @{$t->{feed}->{entry}}, 50,
-                               'got 50 entries');
+                               'got 50 entries') or diag explain([$t, $res]);
 
                        $res = $cb->(GET('/public-inbox/atom/COPYING'));
                        is($res->code, 200, 'file Atom feed');
                        $t = XML::TreePP->new->parse($res->content);
-                       ok($t->{feed}->{entry}, 'got entry');
+                       ok($t->{feed}->{entry}, 'got entry') or
+                               diag explain([ $t, $res ]);
 
                        $res = $cb->(GET('/public-inbox/atom/README.md'));
                        is($res->code, 404, '404 on missing file Atom feed');