1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 20:01:15 +02:00

Use cached result if there is a network error

This commit is contained in:
Eelco Dolstra 2015-04-09 12:49:13 +02:00
parent 1fc905ad4c
commit 4ed2187377
3 changed files with 15 additions and 8 deletions

View file

@ -1551,20 +1551,25 @@ 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);
auto res = downloadFile(url, expectedETag);
try {
auto res = downloadFile(url, expectedETag);
if (!res.cached)
storePath = store->addTextToStore(name, res.data, PathSet(), state.repair);
if (!res.cached)
storePath = store->addTextToStore(name, res.data, PathSet(), state.repair);
assert(!storePath.empty());
replaceSymlink(storePath, fileLink);
assert(!storePath.empty());
replaceSymlink(storePath, fileLink);
writeFile(dataFile, url + "\n" + res.etag + "\n" + int2String(time(0)) + "\n");
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) {