chiark / gitweb /
wip changes for remote push - break out protocol_read_bytes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 9 Oct 2013 06:18:02 +0000 (07:18 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 9 Oct 2013 06:18:02 +0000 (07:18 +0100)
dgit

diff --git a/dgit b/dgit
index 381b7311946f2e7cf6dac556f3bbed1e026c6684..6bd95e99e2f5ce238623c2774777a7b683ba95ff 100755 (executable)
--- 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 $!;
     }
 }