mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
nix-channel: implement in c++
This commit is contained in:
parent
a6eed133c5
commit
59124228b3
8 changed files with 304 additions and 233 deletions
|
@ -31,7 +31,7 @@ struct CurlDownloader : public Downloader
|
|||
{
|
||||
CURL * curl;
|
||||
ref<std::string> data;
|
||||
string etag, status, expectedETag;
|
||||
string etag, status, expectedETag, effectiveUrl;
|
||||
|
||||
struct curl_slist * requestHeaders;
|
||||
|
||||
|
@ -199,6 +199,11 @@ struct CurlDownloader : public Downloader
|
|||
% url % curl_easy_strerror(res) % res);
|
||||
}
|
||||
|
||||
char *effectiveUrlCStr;
|
||||
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrlCStr);
|
||||
if (effectiveUrlCStr)
|
||||
effectiveUrl = effectiveUrlCStr;
|
||||
|
||||
if (httpStatus == 304) return false;
|
||||
|
||||
return true;
|
||||
|
@ -212,6 +217,7 @@ struct CurlDownloader : public Downloader
|
|||
res.data = data;
|
||||
} else
|
||||
res.cached = true;
|
||||
res.effectiveUrl = effectiveUrl;
|
||||
res.etag = etag;
|
||||
return res;
|
||||
}
|
||||
|
@ -223,6 +229,12 @@ ref<Downloader> makeDownloader()
|
|||
}
|
||||
|
||||
Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpack, const Hash & expectedHash)
|
||||
{
|
||||
string ignored;
|
||||
return downloadCached(store, url_, unpack, ignored, expectedHash);
|
||||
}
|
||||
|
||||
Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpack, string & effectiveUrl, const Hash & expectedHash)
|
||||
{
|
||||
auto url = resolveUri(url_);
|
||||
|
||||
|
@ -259,9 +271,10 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
|
|||
auto ss = tokenizeString<vector<string>>(readFile(dataFile), "\n");
|
||||
if (ss.size() >= 3 && ss[0] == url) {
|
||||
time_t lastChecked;
|
||||
if (string2Int(ss[2], lastChecked) && lastChecked + ttl >= time(0))
|
||||
if (string2Int(ss[2], lastChecked) && lastChecked + ttl >= time(0)) {
|
||||
skip = true;
|
||||
else if (!ss[1].empty()) {
|
||||
effectiveUrl = url_;
|
||||
} else if (!ss[1].empty()) {
|
||||
printMsg(lvlDebug, format("verifying previous ETag ‘%1%’") % ss[1]);
|
||||
expectedETag = ss[1];
|
||||
}
|
||||
|
@ -276,6 +289,7 @@ Path Downloader::downloadCached(ref<Store> store, const string & url_, bool unpa
|
|||
DownloadOptions options;
|
||||
options.expectedETag = expectedETag;
|
||||
auto res = download(url, options);
|
||||
effectiveUrl = res.effectiveUrl;
|
||||
|
||||
if (!res.cached) {
|
||||
ValidPathInfo info;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue