From 16783a26acf7e6be1041b2f85229b23ab8fc4b68 Mon Sep 17 00:00:00 2001 From: Michael Schroeder Date: Thu, 2 Nov 2023 12:50:48 +0100 Subject: [PATCH] Improve ua handling for obs repositories --- PBuild/OBS.pm | 6 ++++-- PBuild/RemoteRepo.pm | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/PBuild/OBS.pm b/PBuild/OBS.pm index 276ae39ef..96555f5e2 100644 --- a/PBuild/OBS.pm +++ b/PBuild/OBS.pm @@ -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; } # diff --git a/PBuild/RemoteRepo.pm b/PBuild/RemoteRepo.pm index a32112c0b..01a283f5c 100644 --- a/PBuild/RemoteRepo.pm +++ b/PBuild/RemoteRepo.pm @@ -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); } # @@ -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'}; @@ -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'};