aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/http-binary-cache-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-07-11 13:13:19 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-07-11 13:13:19 +0200
commit4205234f26211baa787fd18de0256622759fea8a (patch)
tree17c17d92dde257a0cf00a919d6ccf24e36287658 /src/libstore/http-binary-cache-store.cc
parentb0c220c02ec584af282b9c7f493e4a4d2e429f8c (diff)
parent53247d6b116905e7233b1efd6c14845e20d27442 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libstore/http-binary-cache-store.cc')
-rw-r--r--src/libstore/http-binary-cache-store.cc56
1 files changed, 15 insertions, 41 deletions
diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc
index ff2c10354..ea39d4f22 100644
--- a/src/libstore/http-binary-cache-store.cc
+++ b/src/libstore/http-binary-cache-store.cc
@@ -2,7 +2,6 @@
#include "download.hh"
#include "globals.hh"
#include "nar-info-disk-cache.hh"
-#include "retry.hh"
namespace nix {
@@ -136,46 +135,21 @@ protected:
{
checkEnabled();
- struct State
- {
- DownloadRequest request;
- std::function<void()> tryDownload;
- unsigned int attempt = 0;
- State(DownloadRequest && request) : request(request) {}
- };
-
- auto state = std::make_shared<State>(makeRequest(path));
-
- state->tryDownload = [callback, state, this]() {
- getDownloader()->enqueueDownload(state->request,
- {[callback, state, this](std::future<DownloadResult> result) {
- try {
- callback(result.get().data);
- } catch (DownloadError & e) {
- if (e.error == Downloader::NotFound || e.error == Downloader::Forbidden)
- return callback(std::shared_ptr<std::string>());
- ++state->attempt;
- if (state->attempt < state->request.tries && e.isTransient()) {
- auto ms = retrySleepTime(state->attempt);
- warn("%s; retrying in %d ms", e.what(), ms);
- /* We can't sleep here because that would
- block the download thread. So use a
- separate thread for sleeping. */
- std::thread([state, ms]() {
- std::this_thread::sleep_for(std::chrono::milliseconds(ms));
- state->tryDownload();
- }).detach();
- } else {
- maybeDisable();
- callback.rethrow();
- }
- } catch (...) {
- callback.rethrow();
- }
- }});
- };
-
- state->tryDownload();
+ auto request(makeRequest(path));
+
+ getDownloader()->enqueueDownload(request,
+ {[callback, this](std::future<DownloadResult> result) {
+ try {
+ callback(result.get().data);
+ } catch (DownloadError & e) {
+ if (e.error == Downloader::NotFound || e.error == Downloader::Forbidden)
+ return callback(std::shared_ptr<std::string>());
+ maybeDisable();
+ callback.rethrow();
+ } catch (...) {
+ callback.rethrow();
+ }
+ }});
}
};