Skip to content

Commit

Permalink
[backend] more BSHTTP BSServerEvents code sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Sep 24, 2015
1 parent fc7eb3c commit 9f8e82b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
33 changes: 22 additions & 11 deletions src/backend/BSHTTP.pm
Expand Up @@ -23,6 +23,7 @@
package BSHTTP;

use Digest::MD5 ();
use Fcntl qw(:DEFAULT);

use strict;

Expand Down Expand Up @@ -351,26 +352,36 @@ sub cpio_sender {
next;
}
if (exists $file->{'filename'}) {
if (ref($file->{'filename'})) {
*F = $file->{'filename'};
} elsif (!open(F, '<', $file->{'filename'})) {
$errors->{'data'} .= "$file->{'name'}: $file->{'filename'}: $!\n";
my $filename = $file->{'filename'};
if (ref($filename)) {
*F = $filename;
} elsif (!open(F, '<', $filename)) {
$errors->{'data'} .= "$file->{'name'}: $filename: $!\n";
next;
}
@s = stat(F);
if (!@s) {
$errors->{'data'} .= "$file->{'name'}: stat: $!\n";
close F unless ref $filename;
next;
}
if (ref($filename)) {
my $off = sysseek(F, 0, Fcntl::SEEK_CUR) || 0;
$s[7] -= $off if $off > 0;
}
($data, $pad) = makecpiohead($file, \@s);
my $l = $s[7];
my $r = 0;
while(1) {
$r = sysread(F, $data, $l > 8192 ? 8192 : $l, length($data)) if $l;
$data .= $pad if $r == $l;
$r = sysread(F, $data, $l > 8192 ? 8192 : $l, length($data)) if $l;
$data .= $pad if $r == $l;
swrite($sock, $data, $param->{'chunked'});
$data = '';
$l -= $r;
last unless $l;
$data = '';
$l -= $r;
last unless $l;
}
die("internal error\n") if $l;
close F unless ref $file->{'filename'};
close F unless ref $filename;
} else {
next if $file->{'__errors'} && $file->{'data'} eq '';
$s[7] = length($file->{'data'});
Expand All @@ -379,7 +390,7 @@ sub cpio_sender {
$data .= "$file->{'data'}$pad";
while ($param->{'chunked'} && length($data) > 8192) {
# keep chunks small
swrite($sock, substr($data, 0, 4096), $param->{'chunked'});
swrite($sock, substr($data, 0, 4096), $param->{'chunked'});
$data = substr($data, 4096);
}
swrite($sock, $data, $param->{'chunked'});
Expand Down
13 changes: 9 additions & 4 deletions src/backend/BSServerEvents.pm
Expand Up @@ -241,12 +241,17 @@ sub cpio_nextfile {
if (!ref($fd)) {
$fd = gensym;
if (!open($fd, '<', $file->{'filename'})) {
$ev->{'cpioerrors'} .= "$file->{'name'}: $!\n";
$ev->{'cpioerrors'} .= "$file->{'name'}: $file->{'filename'}: $!\n";
next;
}
@s = stat($fd);
} else {
@s = stat($fd);
}
@s = stat($fd);
if (!@s) {
$ev->{'cpioerrors'} .= "$file->{'name'}: stat: $!\n";
close($fd) if !ref($file->{'filename'});
next;
}
if (ref($file->{'filename'})) {
my $off = sysseek($fd, 0, Fcntl::SEEK_CUR) || 0;
$s[7] -= $off if $off > 0;
}
Expand Down

0 comments on commit 9f8e82b

Please sign in to comment.