Merge pull request #223261 from xworld21/copy-tarballs-use-all-urls

copy-tarballs: use all the urls of each file

authored by Arnout Engelen and committed by GitHub 0374d789 4579dfb9

+55 -52
+51 -48
maintainers/scripts/copy-tarballs.pl
··· 162 # Check every fetchurl call discovered by find-tarballs.nix. 163 my $mirrored = 0; 164 my $have = 0; 165 - foreach my $fetch (sort { $a->{url} cmp $b->{url} } @{$fetches}) { 166 - my $url = $fetch->{url}; 167 my $algo = $fetch->{type}; 168 my $hash = $fetch->{hash}; 169 my $name = $fetch->{name}; 170 my $isPatch = $fetch->{isPatch}; 171 172 if ($hash =~ /^([a-z0-9]+)-([A-Za-z0-9+\/=]+)$/) { 173 $algo = $1; ··· 183 chomp $hash; 184 } 185 186 - if (defined $ENV{DEBUG}) { 187 - print "$url $algo $hash\n"; 188 - next; 189 - } 190 191 - if ($url !~ /^http:/ && $url !~ /^https:/ && $url !~ /^ftp:/ && $url !~ /^mirror:/) { 192 - print STDERR "skipping $url (unsupported scheme)\n"; 193 - next; 194 - } 195 196 - if ($isPatch) { 197 - print STDERR "skipping $url (support for patches is missing)\n"; 198 - next; 199 - } 200 201 - next if defined $exclude && $url =~ /$exclude/; 202 203 - if (alreadyMirrored($algo, $hash)) { 204 - $have++; 205 - next; 206 - } 207 208 - my $storePath = makeFixedOutputPath(0, $algo, $hash, $name); 209 210 - print STDERR "mirroring $url ($storePath, $algo, $hash)...\n"; 211 212 - if ($dryRun) { 213 - $mirrored++; 214 - next; 215 - } 216 217 - # Substitute the output. 218 - if (!isValidPath($storePath)) { 219 - system("nix-store", "-r", $storePath); 220 - } 221 222 - # Otherwise download the file using nix-prefetch-url. 223 - if (!isValidPath($storePath)) { 224 - $ENV{QUIET} = 1; 225 - $ENV{PRINT_PATH} = 1; 226 - my $fh; 227 - my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; 228 - waitpid($pid, 0) or die; 229 - if ($? != 0) { 230 - print STDERR "failed to fetch $url: $?\n"; 231 - next; 232 - } 233 - <$fh>; my $storePath2 = <$fh>; chomp $storePath2; 234 - if ($storePath ne $storePath2) { 235 - warn "strange: $storePath != $storePath2\n"; 236 - next; 237 - } 238 } 239 - 240 - uploadFile($storePath, $url); 241 - $mirrored++; 242 } 243 244 print STDERR "mirrored $mirrored files, already have $have files\n";
··· 162 # Check every fetchurl call discovered by find-tarballs.nix. 163 my $mirrored = 0; 164 my $have = 0; 165 + foreach my $fetch (sort { $a->{urls}->[0] cmp $b->{urls}->[0] } @{$fetches}) { 166 + my $urls = $fetch->{urls}; 167 my $algo = $fetch->{type}; 168 my $hash = $fetch->{hash}; 169 my $name = $fetch->{name}; 170 my $isPatch = $fetch->{isPatch}; 171 + 172 + if ($isPatch) { 173 + print STDERR "skipping $urls->[0] (support for patches is missing)\n"; 174 + next; 175 + } 176 177 if ($hash =~ /^([a-z0-9]+)-([A-Za-z0-9+\/=]+)$/) { 178 $algo = $1; ··· 188 chomp $hash; 189 } 190 191 + my $storePath = makeFixedOutputPath(0, $algo, $hash, $name); 192 193 + for my $url (@$urls) { 194 + if (defined $ENV{DEBUG}) { 195 + print "$url $algo $hash\n"; 196 + next; 197 + } 198 199 + if ($url !~ /^http:/ && $url !~ /^https:/ && $url !~ /^ftp:/ && $url !~ /^mirror:/) { 200 + print STDERR "skipping $url (unsupported scheme)\n"; 201 + next; 202 + } 203 204 + next if defined $exclude && $url =~ /$exclude/; 205 206 + if (alreadyMirrored($algo, $hash)) { 207 + $have++; 208 + last; 209 + } 210 211 + print STDERR "mirroring $url ($storePath, $algo, $hash)...\n"; 212 213 + if ($dryRun) { 214 + $mirrored++; 215 + last; 216 + } 217 218 + # Substitute the output. 219 + if (!isValidPath($storePath)) { 220 + system("nix-store", "-r", $storePath); 221 + } 222 223 + # Otherwise download the file using nix-prefetch-url. 224 + if (!isValidPath($storePath)) { 225 + $ENV{QUIET} = 1; 226 + $ENV{PRINT_PATH} = 1; 227 + my $fh; 228 + my $pid = open($fh, "-|", "nix-prefetch-url", "--type", $algo, $url, $hash) or die; 229 + waitpid($pid, 0) or die; 230 + if ($? != 0) { 231 + print STDERR "failed to fetch $url: $?\n"; 232 + next; 233 + } 234 + <$fh>; my $storePath2 = <$fh>; chomp $storePath2; 235 + if ($storePath ne $storePath2) { 236 + warn "strange: $storePath != $storePath2\n"; 237 + next; 238 + } 239 + } 240 241 + uploadFile($storePath, $url); 242 + $mirrored++; 243 + last; 244 } 245 } 246 247 print STDERR "mirrored $mirrored files, already have $have files\n";
+4 -4
maintainers/scripts/find-tarballs.nix
··· 9 10 root = expr; 11 12 - uniqueUrls = map (x: x.file) (genericClosure { 13 - startSet = map (file: { key = file.url; inherit file; }) urls; 14 operator = const [ ]; 15 }); 16 17 - urls = map (drv: { url = head (drv.urls or [ drv.url ]); hash = drv.outputHash; isPatch = (drv?postFetch && drv.postFetch != ""); type = drv.outputHashAlgo; name = drv.name; }) fetchurlDependencies; 18 19 fetchurlDependencies = 20 filter ··· 47 48 canEval = val: (builtins.tryEval val).success; 49 50 - in uniqueUrls
··· 9 10 root = expr; 11 12 + uniqueFiles = map (x: x.file) (genericClosure { 13 + startSet = map (file: { key = with file; (if type == null then "" else type + "+") + hash; inherit file; }) files; 14 operator = const [ ]; 15 }); 16 17 + files = map (drv: { urls = drv.urls or [ drv.url ]; hash = drv.outputHash; isPatch = (drv?postFetch && drv.postFetch != ""); type = drv.outputHashAlgo; name = drv.name; }) fetchurlDependencies; 18 19 fetchurlDependencies = 20 filter ··· 47 48 canEval = val: (builtins.tryEval val).success; 49 50 + in uniqueFiles