diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2013-10-09 07:18:02 +0100 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2013-10-09 07:18:02 +0100 |
commit | 76708972d08328b32cef22ec1cf86d0aec1541fa (patch) | |
tree | e86efce9913d29a803dbf7c86b0921d4f594a054 | |
parent | e8b6fa044b8df746e84aa034a44d7c96156cc546 (diff) |
wip changes for remote push - break out protocol_read_bytes
-rwxr-xr-x | dgit | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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 $!; } } |