1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-06 21:41:48 +02:00

Refactor downloadCached() interface

(cherry picked from commit df3f5a78d5)
This commit is contained in:
Eelco Dolstra 2019-05-22 23:36:29 +02:00
parent 7b9c68766d
commit f8b30338ac
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
6 changed files with 63 additions and 49 deletions

View file

@ -86,10 +86,12 @@ static void update(const StringSet & channelNames)
// We want to download the url to a file to see if it's a tarball while also checking if we
// got redirected in the process, so that we can grab the various parts of a nix channel
// definition from a consistent location if the redirect changes mid-download.
std::string effectiveUrl;
CachedDownloadRequest request(url);
request.ttl = 0;
auto dl = getDownloader();
auto filename = dl->downloadCached(store, url, false, "", Hash(), &effectiveUrl, 0).path;
url = chomp(std::move(effectiveUrl));
auto result = dl->downloadCached(store, request);
auto filename = result.path;
url = chomp(result.effectiveUri);
// If the URL contains a version number, append it to the name
// attribute (so that "nix-env -q" on the channels profile
@ -121,12 +123,10 @@ static void update(const StringSet & channelNames)
}
// Download the channel tarball.
auto fullURL = url + "/nixexprs.tar.xz";
try {
filename = dl->downloadCached(store, fullURL, false).path;
filename = dl->downloadCached(store, CachedDownloadRequest(url + "/nixexprs.tar.xz")).path;
} catch (DownloadError & e) {
fullURL = url + "/nixexprs.tar.bz2";
filename = dl->downloadCached(store, fullURL, false).path;
filename = dl->downloadCached(store, CachedDownloadRequest(url + "/nixexprs.tar.bz2")).path;
}
chomp(filename);
}