forked from lix-project/lix
Use cached result if there is a network error
This commit is contained in:
parent
1fc905ad4c
commit
4ed2187377
|
@ -100,7 +100,7 @@ struct Curl
|
|||
CURLcode res = curl_easy_perform(curl);
|
||||
if (res == CURLE_WRITE_ERROR && etag == expectedETag) return false;
|
||||
if (res != CURLE_OK)
|
||||
throw Error(format("unable to download ‘%1%’: %2% (%3%)")
|
||||
throw DownloadError(format("unable to download ‘%1%’: %2% (%3%)")
|
||||
% url % curl_easy_strerror(res) % res);
|
||||
|
||||
long httpStatus = 0;
|
||||
|
|
|
@ -13,4 +13,6 @@ struct DownloadResult
|
|||
|
||||
DownloadResult downloadFile(string url, string expectedETag = "");
|
||||
|
||||
MakeError(DownloadError, Error)
|
||||
|
||||
}
|
||||
|
|
|
@ -1551,11 +1551,12 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
|||
|
||||
if (!skip) {
|
||||
|
||||
if (expectedETag.empty())
|
||||
if (storePath.empty())
|
||||
printMsg(lvlInfo, format("downloading ‘%1%’...") % url);
|
||||
else
|
||||
printMsg(lvlInfo, format("checking ‘%1%’...") % url);
|
||||
|
||||
try {
|
||||
auto res = downloadFile(url, expectedETag);
|
||||
|
||||
if (!res.cached)
|
||||
|
@ -1565,6 +1566,10 @@ void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
|
|||
replaceSymlink(storePath, fileLink);
|
||||
|
||||
writeFile(dataFile, url + "\n" + res.etag + "\n" + int2String(time(0)) + "\n");
|
||||
} catch (DownloadError & e) {
|
||||
if (storePath.empty()) throw;
|
||||
printMsg(lvlError, format("warning: %1%; using cached result") % e.msg());
|
||||
}
|
||||
}
|
||||
|
||||
if (unpack) {
|
||||
|
|
Loading…
Reference in a new issue