diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-04-09T10·49+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2015-04-09T10·49+0200 |
commit | 4ed2187377bb915c0eac7f93f20afa3d16f79a5d (patch) | |
tree | 5742d0b717f424c7ccd4402def7a5cce8a721509 /src/libexpr/primops.cc | |
parent | 1fc905ad4c6320d7625d7f9bec06e70531bb0d5f (diff) |
Use cached result if there is a network error
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 33ec26d260d4..8823efe82e62 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -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) { |