Skip to content

Commit 811730a

Browse files
authored
tests.fetchtorrent: verify and delete in postFetch (NixOS#458193)
2 parents a4eb3be + 92fe934 commit 811730a

File tree

3 files changed

+76
-25
lines changed

3 files changed

+76
-25
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1755c55e08aec3872db177464e0bc3f48c89aa40c1ec32605b472d88f6e92963eb08a10aa37bc47e837ae693db18652f40dfbcd6bf26f07278f0566a19c72cd5 poster.jpg
2+
3ec33eae8153b6e2bdfff8157b332e6f0cfbc14d0c30e6a34042deecf0cff01ee19ca54314678b5ad970ae669da8cb91425e96253caf91d95ae01a62917827b7 Sintel.de.srt
3+
ceac1ea59a9224b26946c6683acfaae27e1551c696fb2c632b55151c17f3faa8f930bbd93904cd7a13a896ad3d670b01e2f2bc1a8851060e05fedd85f804ba17 Sintel.en.srt
4+
6efbc68f872c212f6579c5a5d42d6c2a60d775d32be8a7badcd147dbfc07b24cb2cc97e04a796af4002fcd4c8860a7061aed5d59a1280e4352d1bbd701d612a8 Sintel.es.srt
5+
5619ad5bc7ca82e7f1f3b5e9197ab6ef6f5edd7293d396a3c036fef95d5ef592cf9e8d403e8532f4ba71a93fc9556614bfba3473eceae392d2e3175116c06f95 Sintel.fr.srt
6+
fa93c051491b4e11f8e7a643c2138198f795315c942134b94ceace1adda4a5b28dc58b01b507e0da4c26784fc968f47bca1409f985eec2bf80c3e694662ed7c5 Sintel.it.srt
7+
63426110ed7aa60ed3525078fa324cef4276393b4ada55e0a8cf8292500fdd59c2984e299a4e4f65e4f273b8ae2624da22700de4a55054b00e9d987f606c3c7f Sintel.mp4
8+
5fb04c25fda9dada8c808a9f289cec2cca001d60966b69d61ad663240a869c76dd0aff605122823ccbe199e266331f6a4b11a414bba92999a7041c4b534ef432 Sintel.nl.srt
9+
510f052cbbda0b9fc31679b9a26cc16766df9054fc15b66cff475975725a1e8452e69a28a6f90bb965330a49e49bbf42a90efb13de07eaece7d273ef1ca7978a Sintel.pl.srt
10+
510dc0eca608bd0fdd9633ea80365c916f8c4f0fd8e2fdf77534f455f03814401d210df47d940be4fd2fb7ab4c3ff5038a548846c5fa9badbe77b1731b3cae29 Sintel.pt.srt
11+
57c014bd3d781a94850f85fd6c9364421e17cb2c4e25e22c0a8578f50c874e3f2eaf5a0b3da615db7dc95efbe2e6be7c7238e2e1ba27671c818b9e34b05ee1d0 Sintel.ru.srt
20.3 KB
Binary file not shown.

pkgs/build-support/fetchtorrent/tests.nix

Lines changed: 65 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,130 @@
22
lib,
33
testers,
44
fetchtorrent,
5+
emptyDirectory,
56
...
67
}:
78

89
let
10+
# This meta attribute isn't used anywhere, as the actual derivation
11+
# realizations are only empty directories. It's maintained here as a record
12+
# of the details of the intermediate product that exists briefly while
13+
# building the test derivations.
14+
#
15+
# Ideally we'd use a smaller download, but neither of the Bittorrent backends
16+
# supported by fetchtorrent appear to support torrents that are only reliably
17+
# seeded by HTTP sources rather than other people using Bittorrent clients.
18+
# Sintel was the smallest torrent I could find that had a free license and
19+
# was reliably seeded by other Bittorrent clients.
20+
#
21+
# For more information, see the discussion at
22+
# https://github.com/NixOS/nixpkgs/pull/432091/files/bd13421b2b70f3f125061018c800439ef2d43e8d#r2264073113
923
sintel.meta = {
1024
description = "An open source short film to show off open source technologies.";
1125
longDescription = ''
1226
An independently produced short film, initiated by the Blender Foundation
13-
as a means to further improve andvalidate the free/open source 3D
27+
as a means to further improve and validate the free/open source 3D
1428
creation suite Blender.
1529
'';
1630
license = lib.licenses.cc-by-30;
1731
homepage = "https://durian.blender.org/";
1832
};
1933

2034
# Via https://webtorrent.io/free-torrents
21-
http.url = "https://webtorrent.io/torrents/sintel.torrent";
35+
http.url = "${./test-sintel.torrent}";
2236
magnet.url = "magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent";
2337

24-
flattened.hash = "sha256-EzbmBiTEWOlFUNaV5R4eDeD9EBbp6d93rfby88ACg0s=";
25-
unflattened.hash = "sha256-lVrlo1AwmFcxwsIsY976VYqb3hAprFH1xWYdmlTuw0U=";
38+
# Sintel isn't a massive download, but it's not small. There's also no real
39+
# value in storing copies of it in Nix caches, which is what happens by
40+
# default when this test succeeds. Avoid that by verifying the downloaded
41+
# files using `sha512sum` in the post-fetch hook, then deleting the files so
42+
# the actual derivation result is an empty directory.
43+
#
44+
# Chain `&&` in the postFetch phase because the transmission backend does not
45+
# run that phase with `errexit` enabled.
46+
flattened.postFetch = ''
47+
pushd "$out" &&
48+
sha512sum --check --strict ${./test-hashes.sha512sum} &&
49+
sed 's/.* //' ${./test-hashes.sha512sum} | xargs rm --verbose &&
50+
popd
51+
'';
52+
unflattened.postFetch = ''
53+
pushd "$out" &&
54+
pushd Sintel &&
55+
sha512sum --check --strict ${./test-hashes.sha512sum} &&
56+
sed 's/.* //' ${./test-hashes.sha512sum} | xargs rm --verbose &&
57+
popd &&
58+
rm --dir --verbose Sintel &&
59+
popd
60+
'';
61+
62+
# Fixed output derivation hash is identical for all derivations: the empty
63+
# directory.
64+
fetchtorrentWithHash =
65+
args:
66+
fetchtorrent (
67+
{
68+
hash = builtins.convertHash {
69+
hash = emptyDirectory.outputHash;
70+
toHashFormat = "sri";
71+
hashAlgo = emptyDirectory.outputHashAlgo;
72+
};
73+
}
74+
// args
75+
);
2676
in
2777
# Seems almost but not quite worth using lib.mapCartesianProduct...
28-
builtins.mapAttrs (n: v: testers.invalidateFetcherByDrvHash fetchtorrent v) {
78+
builtins.mapAttrs (n: v: testers.invalidateFetcherByDrvHash fetchtorrentWithHash v) {
2979
http-link = {
3080
inherit (http) url;
31-
inherit (flattened) hash;
32-
inherit (sintel) meta;
81+
inherit (flattened) postFetch;
3382
};
3483
http-link-transmission = {
3584
inherit (http) url;
3685
backend = "transmission";
37-
inherit (flattened) hash;
38-
inherit (sintel) meta;
86+
inherit (flattened) postFetch;
3987
};
4088
magnet-link = {
4189
inherit (magnet) url;
42-
inherit (flattened) hash;
43-
inherit (sintel) meta;
90+
inherit (flattened) postFetch;
4491
};
4592
magnet-link-transmission = {
4693
inherit (magnet) url;
4794
backend = "transmission";
48-
inherit (flattened) hash;
49-
inherit (sintel) meta;
95+
inherit (flattened) postFetch;
5096
};
5197
http-link-rqbit = {
5298
inherit (http) url;
5399
backend = "rqbit";
54-
inherit (flattened) hash;
55-
inherit (sintel) meta;
100+
inherit (flattened) postFetch;
56101
};
57102
magnet-link-rqbit = {
58103
inherit (magnet) url;
59104
backend = "rqbit";
60-
inherit (flattened) hash;
61-
inherit (sintel) meta;
105+
inherit (flattened) postFetch;
62106
};
63107
http-link-rqbit-flattened = {
64108
inherit (http) url;
65109
backend = "rqbit";
66110
flatten = true;
67-
inherit (flattened) hash;
68-
inherit (sintel) meta;
111+
inherit (flattened) postFetch;
69112
};
70113
magnet-link-rqbit-flattened = {
71114
inherit (magnet) url;
72115
backend = "rqbit";
73116
flatten = true;
74-
inherit (flattened) hash;
75-
inherit (sintel) meta;
117+
inherit (flattened) postFetch;
76118
};
77119
http-link-rqbit-unflattened = {
78120
inherit (http) url;
79121
backend = "rqbit";
80122
flatten = false;
81-
inherit (unflattened) hash;
82-
inherit (sintel) meta;
123+
inherit (unflattened) postFetch;
83124
};
84125
magnet-link-rqbit-unflattened = {
85126
inherit (magnet) url;
86127
backend = "rqbit";
87128
flatten = false;
88-
inherit (unflattened) hash;
89-
inherit (sintel) meta;
129+
inherit (unflattened) postFetch;
90130
};
91131
}

0 commit comments

Comments
 (0)