From 8fd7b69da1b32bce2a60557154792f2fd72b0522 Mon Sep 17 00:00:00 2001 From: Vincenzo Mantova <1962985+xworld21@users.noreply.github.com> Date: Sun, 26 Mar 2023 15:49:49 +0100 Subject: copy-tarballs: use all the urls of each file If a file specifies multiple urls, try fetching all of them until nix-prefetch-url is successful. --- maintainers/scripts/copy-tarballs.pl | 99 +++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 48 deletions(-) (limited to 'maintainers/scripts/copy-tarballs.pl') diff --git a/maintainers/scripts/copy-tarballs.pl b/maintainers/scripts/copy-tarballs.pl index c81b49bfb5993..c2e9326d8f63b 100755 --- a/maintainers/scripts/copy-tarballs.pl +++ b/maintainers/scripts/copy-tarballs.pl @@ -159,13 +159,18 @@ elsif (defined $expr) { # Check every fetchurl call discovered by find-tarballs.nix. my $mirrored = 0; my $have = 0; - foreach my $fetch (sort { $a->{url} cmp $b->{url} } @{$fetches}) { - my $url = $fetch->{url}; + foreach my $fetch (sort { $a->{urls}->[0] cmp $b->{urls}->[0] } @{$fetches}) { + my $urls = $fetch->{urls}; my $algo = $fetch->{type}; my $hash = $fetch->{hash}; my $name = $fetch->{name}; my $isPatch = $fetch->{isPatch}; + if ($isPatch) { + print STDERR "skipping $urls->[0] (support for patches is missing)\n"; + next; + } + if ($hash =~ /^([a-z0-9]+)-([A-Za-z0-9+\/=]+)$/) { $algo = $1; $hash = `nix hash to-base16 $hash` or die; @@ -180,62 +185,60 @@ elsif (defined $expr) { chomp $hash; } - if (defined $ENV{DEBUG}) { - print "$url $algo $hash\n"; - next; - } - - if ($url !~ /^http:/ && $url !~ /^https:/ && $url !~ /^ftp:/ && $url !~ /^mirror:/) { - print STDERR "skipping $url (unsupported scheme)\n"; - next; - } - - if ($isPatch) { - print STDERR "skipping $url (support for patches is missing)\n"; - next; - } + my $storePath = makeFixedOutputPath(0, $algo, $hash, $name); - next if defined $exclude && $url =~ /$exclude/; + for my $url (@$urls) { + if (defined $ENV{DEBUG}) { + print "$url $algo $hash\n"; + next; + } - if (alreadyMirrored($algo, $hash)) { - $have++; - next; - } + if ($url !~ /^http:/ && $url !~ /^https:/ && $url !~ /^ftp:/ && $url !~ /^mirror:/) { + print STDERR "skipping $url (unsupported scheme)\n"; + next; + } - my $storePath = makeFixedOutputPath(0, $algo, $hash, $name); + next if defined $exclude && $url =~ /$exclude/; - print STDERR "mirroring $url ($storePath, $algo, $hash)...\n"; + if (alreadyMirrored($algo, $hash)) { + $have++; + last; + } - if ($dryRun) { - $mirrored++; - next; - } + print STDERR "mirroring $url ($storePath, $algo, $hash)...\n"; - # Substitute the output. - if (!isValidPath($storePath)) { - system("nix-store", "-r", $storePath); - } + if ($dryRun) { + $mirrored++; + last; + } - # Otherwise download the file using nix-prefetch-url. - if (!isValidPath($storePath)) { - $ENV{QUIET} = 1; - $ENV{PRINT_PATH} = 1; - my $fh; - my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; - waitpid($pid, 0) or die; - if ($? != 0) { - print STDERR "failed to fetch $url: $?\n"; - next; + # Substitute the output. + if (!isValidPath($storePath)) { + system("nix-store", "-r", $storePath); } - <$fh>; my $storePath2 = <$fh>; chomp $storePath2; - if ($storePath ne $storePath2) { - warn "strange: $storePath != $storePath2\n"; - next; + + # Otherwise download the file using nix-prefetch-url. + if (!isValidPath($storePath)) { + $ENV{QUIET} = 1; + $ENV{PRINT_PATH} = 1; + my $fh; + my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; + waitpid($pid, 0) or die; + if ($? != 0) { + print STDERR "failed to fetch $url: $?\n"; + next; + } + <$fh>; my $storePath2 = <$fh>; chomp $storePath2; + if ($storePath ne $storePath2) { + warn "strange: $storePath != $storePath2\n"; + next; + } } - } - uploadFile($storePath, $url); - $mirrored++; + uploadFile($storePath, $url); + $mirrored++; + last; + } } print STDERR "mirrored $mirrored files, already have $have files\n"; -- cgit 1.4.1