Skip to content

Commit 0374d78

Browse files
authored
Merge pull request #223261 from xworld21/copy-tarballs-use-all-urls
copy-tarballs: use all the urls of each file
2 parents 4579dfb + 8fd7b69 commit 0374d78

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed

maintainers/scripts/copy-tarballs.pl

+51-48
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,18 @@ sub uploadFile {
162162
# Check every fetchurl call discovered by find-tarballs.nix.
163163
my $mirrored = 0;
164164
my $have = 0;
165-
foreach my $fetch (sort { $a->{url} cmp $b->{url} } @{$fetches}) {
166-
my $url = $fetch->{url};
165+
foreach my $fetch (sort { $a->{urls}->[0] cmp $b->{urls}->[0] } @{$fetches}) {
166+
my $urls = $fetch->{urls};
167167
my $algo = $fetch->{type};
168168
my $hash = $fetch->{hash};
169169
my $name = $fetch->{name};
170170
my $isPatch = $fetch->{isPatch};
171171

172+
if ($isPatch) {
173+
print STDERR "skipping $urls->[0] (support for patches is missing)\n";
174+
next;
175+
}
176+
172177
if ($hash =~ /^([a-z0-9]+)-([A-Za-z0-9+\/=]+)$/) {
173178
$algo = $1;
174179
$hash = `nix hash to-base16 $hash` or die;
@@ -183,62 +188,60 @@ sub uploadFile {
183188
chomp $hash;
184189
}
185190

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-
}
191+
my $storePath = makeFixedOutputPath(0, $algo, $hash, $name);
200192

201-
next if defined $exclude && $url =~ /$exclude/;
193+
for my $url (@$urls) {
194+
if (defined $ENV{DEBUG}) {
195+
print "$url $algo $hash\n";
196+
next;
197+
}
202198

203-
if (alreadyMirrored($algo, $hash)) {
204-
$have++;
205-
next;
206-
}
199+
if ($url !~ /^http:/ && $url !~ /^https:/ && $url !~ /^ftp:/ && $url !~ /^mirror:/) {
200+
print STDERR "skipping $url (unsupported scheme)\n";
201+
next;
202+
}
207203

208-
my $storePath = makeFixedOutputPath(0, $algo, $hash, $name);
204+
next if defined $exclude && $url =~ /$exclude/;
209205

210-
print STDERR "mirroring $url ($storePath, $algo, $hash)...\n";
206+
if (alreadyMirrored($algo, $hash)) {
207+
$have++;
208+
last;
209+
}
211210

212-
if ($dryRun) {
213-
$mirrored++;
214-
next;
215-
}
211+
print STDERR "mirroring $url ($storePath, $algo, $hash)...\n";
216212

217-
# Substitute the output.
218-
if (!isValidPath($storePath)) {
219-
system("nix-store", "-r", $storePath);
220-
}
213+
if ($dryRun) {
214+
$mirrored++;
215+
last;
216+
}
221217

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;
218+
# Substitute the output.
219+
if (!isValidPath($storePath)) {
220+
system("nix-store", "-r", $storePath);
232221
}
233-
<$fh>; my $storePath2 = <$fh>; chomp $storePath2;
234-
if ($storePath ne $storePath2) {
235-
warn "strange: $storePath != $storePath2\n";
236-
next;
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+
}
237239
}
238-
}
239240

240-
uploadFile($storePath, $url);
241-
$mirrored++;
241+
uploadFile($storePath, $url);
242+
$mirrored++;
243+
last;
244+
}
242245
}
243246

244247
print STDERR "mirrored $mirrored files, already have $have files\n";

maintainers/scripts/find-tarballs.nix

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ let
99

1010
root = expr;
1111

12-
uniqueUrls = map (x: x.file) (genericClosure {
13-
startSet = map (file: { key = file.url; inherit file; }) urls;
12+
uniqueFiles = map (x: x.file) (genericClosure {
13+
startSet = map (file: { key = with file; (if type == null then "" else type + "+") + hash; inherit file; }) files;
1414
operator = const [ ];
1515
});
1616

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;
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;
1818

1919
fetchurlDependencies =
2020
filter
@@ -47,4 +47,4 @@ let
4747

4848
canEval = val: (builtins.tryEval val).success;
4949

50-
in uniqueUrls
50+
in uniqueFiles

0 commit comments

Comments
 (0)