mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 00:39:37 +01:00
downloader: when retry but can't resume, retry the whole file
This commit is contained in:
parent
e322a16523
commit
7827af1b67
1 changed files with 7 additions and 9 deletions
|
|
@ -308,7 +308,7 @@ struct CurlDownloader : public Downloader
|
||||||
curl_easy_setopt(req, CURLOPT_NETRC_FILE, settings.netrcFile.get().c_str());
|
curl_easy_setopt(req, CURLOPT_NETRC_FILE, settings.netrcFile.get().c_str());
|
||||||
curl_easy_setopt(req, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
|
curl_easy_setopt(req, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
|
||||||
|
|
||||||
if (writtenToSink)
|
if (writtenToSink && acceptRanges && encoding.empty())
|
||||||
curl_easy_setopt(req, CURLOPT_RESUME_FROM_LARGE, writtenToSink);
|
curl_easy_setopt(req, CURLOPT_RESUME_FROM_LARGE, writtenToSink);
|
||||||
|
|
||||||
result.data = std::make_shared<std::string>();
|
result.data = std::make_shared<std::string>();
|
||||||
|
|
@ -414,16 +414,14 @@ struct CurlDownloader : public Downloader
|
||||||
|
|
||||||
/* If this is a transient error, then maybe retry the
|
/* If this is a transient error, then maybe retry the
|
||||||
download after a while. If we're writing to a
|
download after a while. If we're writing to a
|
||||||
sink, we can only retry if the server supports
|
sink, we can only resume if the server supports
|
||||||
ranged requests. */
|
ranged requests, otherwise fallback to a plain
|
||||||
if (err == Transient
|
retry.
|
||||||
&& attempt < request.tries
|
*/
|
||||||
&& (!this->request.dataCallback
|
if (err == Transient && attempt < request.tries)
|
||||||
|| writtenToSink == 0
|
|
||||||
|| (acceptRanges && encoding.empty())))
|
|
||||||
{
|
{
|
||||||
int ms = request.baseRetryTimeMs * std::pow(2.0f, attempt - 1 + std::uniform_real_distribution<>(0.0, 0.5)(downloader.mt19937));
|
int ms = request.baseRetryTimeMs * std::pow(2.0f, attempt - 1 + std::uniform_real_distribution<>(0.0, 0.5)(downloader.mt19937));
|
||||||
if (writtenToSink)
|
if (writtenToSink && acceptRanges && encoding.empty())
|
||||||
warn("%s; retrying from offset %d in %d ms", exc.what(), writtenToSink, ms);
|
warn("%s; retrying from offset %d in %d ms", exc.what(), writtenToSink, ms);
|
||||||
else
|
else
|
||||||
warn("%s; retrying in %d ms", exc.what(), ms);
|
warn("%s; retrying in %d ms", exc.what(), ms);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue