Skip to content

Commit

Permalink
Improve ua handling for obs repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
mlschroe committed Nov 2, 2023
1 parent c89e059 commit 16783a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions PBuild/OBS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,20 @@ sub fetch_binaries_cpioextract {
# Download binaries in batches from a remote obs instance
#
sub fetch_binaries {
my ($url, $repodir, $names, $callback, $ua) = @_;
my ($url, $repodir, $names, $callback) = @_;
my @names = sort keys %$names;
return undef unless @names;
my $ua = create_ua();
while (@names) {
my @nchunk = splice(@names, 0, 100);
my $chunkurl = "$url/_repository?view=cpio";
$chunkurl .= "&binary=".PBuild::Util::urlencode($_) for @nchunk;
my $tmpcpio = "$repodir/.$$.binaries.cpio";
$ua = create_ua($ua);
Build::Download::download($chunkurl, $tmpcpio, undef, 'ua' => $ua, 'retry' => 3);
PBuild::Cpio::cpio_extract($tmpcpio, sub {fetch_binaries_cpioextract($_[0], $_[1], $repodir, $names, $callback)});
unlink($tmpcpio);
}
return $ua;
}

#
Expand Down
9 changes: 5 additions & 4 deletions PBuild/RemoteRepo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ sub fetchbinaries_obs {
next if $1 ne $url;
$names{$bin->{'name'}} = [ ".$$.$binname", $binname, $bin ];
}
return unless %names;
return undef unless %names;
my $repodir = $repo->{'dir'};
PBuild::Util::mkdir_p($repodir);
PBuild::OBS::fetch_binaries($url, $repodir, \%names, \&fetchbinaries_replace, $ua);
return PBuild::OBS::fetch_binaries($url, $repodir, \%names, \&fetchbinaries_replace);
}

#
Expand All @@ -464,8 +464,8 @@ sub fetchbinaries {
die("bad repo\n") unless $url;
print "fetching ".PBuild::Util::plural(scalar(@$bins), 'binary')." from $url\n";
PBuild::Util::mkdir_p($repodir);
my $ua = Build::Download::create_ua();
fetchbinaries_obs($repo, $bins, $ua) if $url =~ /^obs:/;
my $ua;
$ua = fetchbinaries_obs($repo, $bins) if $url =~ /^obs:/;
for my $bin (@$bins) {
next if $bin->{'filename'};
my $location = $bin->{'location'};
Expand All @@ -474,6 +474,7 @@ sub fetchbinaries {
my $binname = calc_binname($bin);
PBuild::Verify::verify_filename($binname);
my $tmpname = ".$$.$binname";
$ua ||= Build::Download::create_ua();
if ($bin->{'name'} =~ /^container:/) {
# we cannot query containers, just download and set the filename
die("container has no hdrmd5\n") unless $bin->{'hdrmd5'};
Expand Down

0 comments on commit 16783a2

Please sign in to comment.