diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-03-19 11:42:50 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-03-19 11:42:50 +0100 |
commit | 1c127e6a82dbc128602aa4451dfa8f4c2fe4a751 (patch) | |
tree | d96519d7c3b0a5c038dd2a7c40c85e0525e299aa /src/libstore | |
parent | f6ddf48882a068dbf1b1bfff44d487316972d6e9 (diff) |
downloadFile(): Use expired file if the download fails
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/fetchers/tarball.cc | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/libstore/fetchers/tarball.cc b/src/libstore/fetchers/tarball.cc index 54b59babc..62d43ca36 100644 --- a/src/libstore/fetchers/tarball.cc +++ b/src/libstore/fetchers/tarball.cc @@ -25,17 +25,31 @@ DownloadFileResult downloadFile( auto cached = getCache()->lookupExpired(store, inAttrs); - if (cached && !cached->expired) + auto useCached = [&]() -> DownloadFileResult + { return { .storePath = std::move(cached->storePath), .etag = getStrAttr(cached->infoAttrs, "etag"), .effectiveUrl = getStrAttr(cached->infoAttrs, "url") }; + }; + + if (cached && !cached->expired) + return useCached(); DownloadRequest request(url); if (cached) request.expectedETag = getStrAttr(cached->infoAttrs, "etag"); - auto res = getDownloader()->download(request); + DownloadResult res; + try { + res = getDownloader()->download(request); + } catch (DownloadError & e) { + if (cached) { + warn("%s; using cached version", e.msg()); + return useCached(); + } else + throw; + } // FIXME: write to temporary file. |