about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-05-02 20:07:59 +0000
committerEric Wong <e@80x24.org>2014-05-02 20:07:59 +0000
commit85f6a372e8bea0b64ff7740c73c7d478fad201c4 (patch)
tree7771d96382c92ff2fa056620d86d91e88458f1e3 /lib
parent55ff8f0893e1a1d57463861e0599717744f490bf (diff)
downloadpublic-inbox-85f6a372e8bea0b64ff7740c73c7d478fad201c4.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/GitCatFile.pm12
1 files changed, 9 insertions, 3 deletions
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>;