From 85f6a372e8bea0b64ff7740c73c7d478fad201c4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 2 May 2014 20:07:59 +0000 Subject: git cat-file wrapper uses syswrite for writes The requests we make to git cat-file --batch are guaranteed to be smaller than the 512 bytes required by PIPE_BUF, so there will be no partial writes. Bypass Perl IO layers and write directly to the pipe to avoid needing IO::Handle here. --- lib/PublicInbox/GitCatFile.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/GitCatFile.pm b/lib/PublicInbox/GitCatFile.pm index b75389e2..8bc6a238 100644 --- a/lib/PublicInbox/GitCatFile.pm +++ b/lib/PublicInbox/GitCatFile.pm @@ -8,7 +8,6 @@ use strict; use warnings; use Fcntl qw(F_GETFD F_SETFD FD_CLOEXEC); use POSIX qw(dup2); -require IO::Handle; sub new { my ($class, $git_dir) = @_; @@ -42,7 +41,6 @@ sub _cat_file_begin { close $out_r or die "close failed: $!\n"; close $in_w or die "close failed: $!\n"; - $out_w->autoflush(1); $self->{in} = $in_r; $self->{out} = $out_w; $self->{pid} = $pid; @@ -51,8 +49,16 @@ sub _cat_file_begin { sub cat_file { my ($self, $object) = @_; + $object .= "\n"; + my $len = bytes::length($object); + $self->_cat_file_begin; - print { $self->{out} } $object, "\n" or die "write error: $!\n"; + my $written = syswrite($self->{out}, $object); + if (!defined $written) { + die "pipe write error: $!\n"; + } elsif ($written != $len) { + die "wrote too little to pipe ($written < $len)\n"; + } my $in = $self->{in}; my $head = <$in>; -- cgit v1.2.3-24-ge0c7