Skip to content

Commit

Permalink
[backend] also support cpio 'offset' parameter in BSServerEvents
Browse files Browse the repository at this point in the history
And switch bs_repserver to use offset instead of seeking.
  • Loading branch information
mlschroe committed Jun 4, 2018
1 parent 7e60011 commit 9f1f68c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/backend/BSCpio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ sub writecpio {
$errors->{'data'} .= $@;
next;
}
$s[7] = $l;
my ($data, $pad) = makecpiohead($ent, \@s);
my $r = 0;
while (1) {
Expand Down
48 changes: 27 additions & 21 deletions src/backend/BSServerEvents.pm
Original file line number Diff line number Diff line change
Expand Up @@ -194,53 +194,59 @@ sub cpio_nextfile {
delete $ev->{'filespad'};
my $files = $ev->{'files'};
my $filesno = defined($ev->{'filesno'}) ? $ev->{'filesno'} + 1 : 0;
my $file;
my $ent;
if ($filesno >= @$files) {
if ($ev->{'cpioerrors'} ne '') {
$file = {'data' => $ev->{'cpioerrors'}, 'name' => '.errors'};
$ent = {'data' => $ev->{'cpioerrors'}, 'name' => '.errors'};
$ev->{'cpioerrors'} = '';
} else {
$data .= BSCpio::makecpiohead();
return $data;
}
} else {
$ev->{'filesno'} = $filesno;
$file = $files->[$filesno];
$ent = $files->[$filesno];
}
if ($file->{'error'}) {
$ev->{'cpioerrors'} .= "$file->{'name'}: $file->{'error'}\n";
my $name = $ent->{'name'};
if ($ent->{'error'}) {
$ev->{'cpioerrors'} .= "$name: $ent->{'error'}\n";
next;
}
my @s;
if (exists $file->{'filename'}) {
my $fd = $file->{'filename'};
if (exists($ent->{'file'}) || exists($ent->{'filename'})) {
my $file = exists($ent->{'file'}) ? $ent->{'file'} : $ent->{'filename'};
my $fd = $file;
if (!ref($fd)) {
$fd = gensym;
if (!open($fd, '<', $file->{'filename'})) {
$ev->{'cpioerrors'} .= "$file->{'name'}: $file->{'filename'}: $!\n";
if (!open($fd, '<', $file)) {
$ev->{'cpioerrors'} .= "$name: $file: $!\n";
next;
}
}
@s = stat($fd);
if (!@s) {
$ev->{'cpioerrors'} .= "$file->{'name'}: stat: $!\n";
$ev->{'cpioerrors'} .= "$name: stat: $!\n";
close($fd);
next;
}
if (ref($file->{'filename'})) {
my $off = sysseek($fd, 0, Fcntl::SEEK_CUR) || 0;
$s[7] -= $off if $off > 0;
if (defined($ent->{'offset'})) {
if (!defined(sysseek($fd, $ent->{'offset'}, 0))) {
$ev->{'cpioerrors'} .= "$name: seek: $!\n";
close($fd);
next;
}
$s[7] -= $ent->{'offset'};
}
$ev->{'fd'} = $fd;
my ($header, $pad) = BSCpio::makecpiohead($ent, \@s);
$data .= $header;
$ev->{'filespad'} = $pad;
} else {
$s[7] = length($file->{'data'});
$s[9] = time();
}
my ($header, $pad) = BSCpio::makecpiohead($file, \@s);
$data .= $header;
$ev->{'filespad'} = $pad;
if (!exists $file->{'filename'}) {
$data .= $file->{'data'};
$s[7] = length($ent->{'data'});
$s[9] = $ent->{'mtime'} || time();
my ($header, $pad) = BSCpio::makecpiohead($ent, \@s);
$data .= "$header$ent->{'data'}";
$ev->{'filespad'} = $pad;
next;
}
return $data;
Expand Down
3 changes: 1 addition & 2 deletions src/backend/bs_repserver
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ sub getbinarylist_repository {
$fd->flush();
BSUtil::do_fdatasync(fileno($fd)) if $BSUtil::fdatasync_before_rename;
rename($tmpname, "$reporoot/$prp/$arch/:full.xcache");
sysseek($fd, 64, Fcntl::SEEK_SET);
push @files, { 'name' => 'repositorycache', 'filename' => $fd };
push @files, { 'name' => 'repositorycache', 'filename' => $fd, 'offset' => 64 };
}
}
undef $repo;
Expand Down

0 comments on commit 9f1f68c

Please sign in to comment.