diff --git a/platform/http_request.cpp b/platform/http_request.cpp index a8f49ff7c9..e044383e96 100644 --- a/platform/http_request.cpp +++ b/platform/http_request.cpp @@ -218,6 +218,9 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback void SaveResumeChunks() { + if (m_writer == nullptr) + return; + try { // Flush writer before saving downloaded chunks. @@ -275,6 +278,11 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback if (m_status != ECompleted && m_goodChunksCount % 10 == 0) SaveResumeChunks(); } + else if (result == ChunksDownloadStrategy::ENoFreeServers) + { + // There is no any server which is able to re-download chunk. + m_status = EFailed; + } if (m_status != EInProgress) { diff --git a/storage/storage.cpp b/storage/storage.cpp index 7d282fad9f..7263d30dc0 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -825,8 +825,7 @@ void Storage::RegisterDownloadedFiles(TCountryId const & countryId, MapOptions o ASSERT_THREAD_CHECKER(m_threadChecker, ()); if (!isSuccess) { - m_failedCountries.insert(countryId); - NotifyStatusChangedForHierarchy(countryId); + OnDownloadFailed(countryId); return; } @@ -907,8 +906,7 @@ void Storage::OnMapDownloadFinished(TCountryId const & countryId, bool success, if (!success) { - m_failedCountries.insert(countryId); - NotifyStatusChangedForHierarchy(countryId); + OnDownloadFailed(countryId); return; } @@ -1452,8 +1450,7 @@ void Storage::OnDiffStatusReceived(diffs::Status const status) ASSERT_THREAD_CHECKER(m_threadChecker, ()); if (!isSuccess) { - m_failedCountries.insert(countryId); - NotifyStatusChangedForHierarchy(countryId); + OnDownloadFailed(countryId); return; } @@ -1884,4 +1881,13 @@ TMwmSize Storage::GetRemoteSize(CountryFile const & file, MapOptions opt, int64_ } return size; } + +void Storage::OnDownloadFailed(TCountryId const & countryId) +{ + m_failedCountries.insert(countryId); + auto it = find(m_queue.cbegin(), m_queue.cend(), countryId); + if (it != m_queue.cend()) + m_queue.erase(it); + NotifyStatusChangedForHierarchy(countryId); +} } // namespace storage diff --git a/storage/storage.hpp b/storage/storage.hpp index 483860eec2..3e95c538ba 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -656,6 +656,8 @@ private: bool IsDisputed(TCountryTreeNode const & node) const; void CalMaxMwmSizeBytes(); + + void OnDownloadFailed(TCountryId const & countryId); void LoadDiffScheme(); void ApplyDiff(TCountryId const & countryId, function const & fn);