From 8a3fc4a2f027b36f27225ceee5908c571c8f4f47 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 4 Mar 2017 03:52:29 +0000 Subject: repoobrowse: explicit EOF handling for git async callback We need to ensure we've fully-drained the pipe before signalling EOF to the callback, since pipelining may not be the best choice with detachable processes in the future. --- lib/PublicInbox/RepoGitSrc.pm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'lib/PublicInbox/RepoGitSrc.pm') diff --git a/lib/PublicInbox/RepoGitSrc.pm b/lib/PublicInbox/RepoGitSrc.pm index 67de86ee..51048773 100644 --- a/lib/PublicInbox/RepoGitSrc.pm +++ b/lib/PublicInbox/RepoGitSrc.pm @@ -154,18 +154,17 @@ sub git_blob_show { return if $ref eq 'ARRAY'; # redundant info if ($ref eq 'SCALAR') { $buf .= $$r; - if (bytes::length($buf) == $size) { - my $fh = $res->($self->rt(200, 'html')); - my $sed = git_blob_sed($req, $hex, $size); - $fh->write($sed->($buf)); - $fh->write($sed->(undef)); - $fh->close; - } - return; + } elsif (!defined $r) { + my $cb = $res or return; + $res = undef; + $cb->($self->rt(500, 'plain', "Error\n")); + } elsif ($r == 0) { + my $fh = $res->($self->rt(200, 'html')); + my $sed = git_blob_sed($req, $hex, $size); + $fh->write($sed->($buf)); + $fh->write($sed->(undef)); + $fh->close; } - my $cb = $res or return; - $res = undef; - $cb->($self->rt(500, 'plain', "Error\n")); }); } -- cgit v1.2.3-24-ge0c7