From 76708972d08328b32cef22ec1cf86d0aec1541fa Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 9 Oct 2013 07:18:02 +0100 Subject: [PATCH] wip changes for remote push - break out protocol_read_bytes --- dgit | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/dgit b/dgit index 381b7311..6bd95e99 100755 --- a/dgit +++ b/dgit @@ -191,15 +191,22 @@ sub protocol_send_file ($$) { close PF; } +sub protocol_read_bytes ($$) { + my ($fh, $nbytes) = @_; + $nbytes =~ m/^\d{1,6}$/ or badproto \*RO, "bad byte count"; + my $d; + my $got = read $fh, $d, $nbytes; + $got==$nbytes or badproto $fh, "eof during data block"; + return $d; +} + sub protocol_receive_file ($$) { my ($fh, $ourfn) = @_; open PF, ">", $ourfn or die "$ourfn: $!"; for (;;) { - protocol_expect \*STDIN, { m/^data-block (\d{1,6})$|data-end$/ }; + protocol_expect \*STDIN, { m/^data-block (.*})$|data-end$/ }; length $1 or last; - my $d; - my $got = read $fh, $d, $1; - $got==$1 or badproto $fh, "eof during data block"; + my $d = protocol_read_bytes \*STDIN, $1; print PF $d or die $!; } } -- 2.30.2