Skip to content

Commit

Permalink
[backend] implement annotation import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Jun 5, 2018
1 parent 9a32135 commit fb00b2b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/backend/BSRepServer/Remote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ use strict;
use BSConfiguration;
use BSRPC ':https';
use BSUtil;
use BSXML;

my $proxy;
$proxy = $BSConfig::proxy if defined($BSConfig::proxy);

sub import_annotation {
my ($annotation) = @_;
return $annotation unless ref($annotation);
my %a;
for (qw{repo disturl buildtime}) {
$a{$_} = $annotation->{$_} if exists $annotation->{$_};
}
return BSUtil::toxml(\%a, $BSXML::binannotation);
}

sub addrepo_remote {
my ($pool, $prp, $arch, $remoteproj) = @_;

Expand All @@ -44,10 +55,13 @@ sub addrepo_remote {
my $cache = BSUtil::fromstorable($cpio{'repositorycache'}, 2);
delete $cpio{'repositorycache'}; # free mem
return undef unless $cache;
# free some unused entries to save mem
# postprocess entries
for (values %$cache) {
# free some unused entries to save mem
delete $_->{'path'};
delete $_->{'id'};
# import annotations
$_->{'annotation'} = import_annotation($_->{'annotation'}) if $_->{'annotation'};
}
delete $cache->{'/external/'};
delete $cache->{'/url'};
Expand Down
16 changes: 15 additions & 1 deletion src/backend/BSSched/Remote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use BSSolv;
use BSRPC;
use BSSched::RPC;
use BSConfiguration;
use BSXML;

=head2 setup_watches - create watches for all dependencies on remote projects
Expand Down Expand Up @@ -399,6 +400,16 @@ sub addrepo_remote_resume {
$ctx->setchanged($handle) unless !$r && $error && BSSched::RPC::is_transient_error($error);
}

sub import_annotation {
my ($annotation) = @_;
return $annotation unless ref($annotation);
my %a;
for (qw{repo disturl buildtime}) {
$a{$_} = $annotation->{$_} if exists $annotation->{$_};
}
return BSUtil::toxml(\%a, $BSXML::binannotation);
}

sub addrepo_remote_unpackcpio {
my ($gctx, $pool, $prp, $arch, $cpio, $solvok, $error) = @_;

Expand Down Expand Up @@ -460,11 +471,14 @@ sub addrepo_remote_unpackcpio {
delete $cache->{'/url'};
delete $cache->{'/dodcookie'};
delete $cache->{'/external/'};
# free some unused entries to save mem
# postprocess entries
for (values %$cache) {
$havedod = 1 if ($_->{'hdrmd5'} || '') eq 'd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0';
# free some unused entries to save mem
delete $_->{'path'};
delete $_->{'id'};
# import annotations
$_->{'annotation'} = import_annotation($_->{'annotation'}) if $_->{'annotation'};
}
# add special "havedod" marker
$cache->{'/dodcookie'} = 'remote repository with dod packages' if $havedod;
Expand Down
13 changes: 7 additions & 6 deletions src/backend/bs_repserver
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,11 @@ sub processavailable {
return \@res;
}

sub mapannotationurls {
my ($p) = @_;
my $annotation = BSUtil::fromxml($p->{'annotation'}, $BSXML::binannotation, 1);
return unless $annotation && $annotation->{'repo'};
sub export_annotation {
my ($annotation_xml) = @_;
my $annotation = BSUtil::fromxml($annotation_xml, $BSXML::binannotation, 1);
return undef unless $annotation;
return $annotation_xml unless $annotation->{'repo'}; # nothing to map
for my $r (@{$annotation->{'repo'}}) {
my $url = $r->{'url'};
next unless $url;
Expand All @@ -552,7 +553,7 @@ sub mapannotationurls {
}
($r->{'project'}, $r->{'repository'}) = split('/', $urlprp, 2) if $urlprp;
}
$p->{'annotation'} = BSUtil::toxml($annotation, $BSXML::binannotation);
return BSUtil::toxml($annotation, $BSXML::binannotation);
}

sub getbinarylist_repository {
Expand Down Expand Up @@ -641,7 +642,7 @@ sub getbinarylist_repository {
my %data = $repo->pkgnames();
for my $p (values %data) {
$p = $pool->pkg2data($p);
mapannotationurls($p) if $p->{'annotation'};
$p->{'annotation'} = export_annotation($p->{'annotation'}) if $p->{'annotation'};
}
if (keys(%data) < 100 && $s[7] < 10000) {
# small repo, feed from memory
Expand Down

0 comments on commit fb00b2b

Please sign in to comment.