summaryrefslogtreecommitdiff
path: root/dgit
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2013-10-09 07:18:02 +0100
committerIan Jackson <ijackson@chiark.greenend.org.uk>2013-10-09 07:18:02 +0100
commit76708972d08328b32cef22ec1cf86d0aec1541fa (patch)
treee86efce9913d29a803dbf7c86b0921d4f594a054 /dgit
parente8b6fa044b8df746e84aa034a44d7c96156cc546 (diff)
wip changes for remote push - break out protocol_read_bytes
Diffstat (limited to 'dgit')
-rwxr-xr-xdgit15
1 files changed, 11 insertions, 4 deletions
diff --git a/dgit b/dgit
index 381b731..6bd95e9 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 $!;
}
}