| 1703 | */ |
| 1704 | |
| 1705 | void Storage::ApplyDiff(CountryId const & countryId, function<void(bool isSuccess)> const & fn) |
| 1706 | { |
| 1707 | LOG(LINFO, ("Applying diff for", countryId)); |
| 1708 | |
| 1709 | if (IsDiffApplyingInProgressToCountry(countryId)) |
| 1710 | return; |
| 1711 | |
| 1712 | auto const diffLocalFile = PreparePlaceForCountryFiles(m_currentVersion, m_dataDir, GetCountryFile(countryId)); |
| 1713 | uint64_t version; |
| 1714 | if (!diffLocalFile || !m_diffsDataSource->VersionFor(countryId, version)) |
| 1715 | { |
| 1716 | fn(false); |
| 1717 | return; |
| 1718 | } |
| 1719 | |
| 1720 | auto const emplaceResult = m_diffsBeingApplied.emplace(countryId, std::make_unique<base::Cancellable>()); |
| 1721 | CHECK_EQUAL(emplaceResult.second, true, ()); |
| 1722 | |
| 1723 | NotifyStatusChangedForHierarchy(countryId); |
| 1724 | |
| 1725 | diffs::ApplyDiffParams params; |
| 1726 | params.m_diffFile = diffLocalFile; |
| 1727 | params.m_diffReadyPath = GetFileDownloadPath(countryId, MapFileType::Diff); |
| 1728 | params.m_oldMwmFile = GetLocalFile(countryId, version); |
| 1729 | |
| 1730 | LocalFilePtr & diffFile = params.m_diffFile; |
| 1731 | diffs::ApplyDiff(std::move(params), *emplaceResult.first->second, |
| 1732 | [this, fn, countryId, diffFile](DiffApplicationResult result) |
| 1733 | { |
| 1734 | CHECK_THREAD_CHECKER(m_threadChecker, ()); |
| 1735 | if (result == DiffApplicationResult::Ok && m_integrityValidationEnabled && !diffFile->ValidateIntegrity()) |
| 1736 | { |
| 1737 | GetPlatform().RunTask(Platform::Thread::File, |
| 1738 | [path = diffFile->GetPath(MapFileType::Map)] { base::DeleteFileX(path); }); |
| 1739 | result = DiffApplicationResult::Failed; |
| 1740 | } |
| 1741 | |
| 1742 | if (m_diffsBeingApplied[countryId]->IsCancelled() && result == DiffApplicationResult::Ok) |
| 1743 | result = DiffApplicationResult::Cancelled; |
| 1744 | |
| 1745 | LOG(LINFO, ("Diff application result for", countryId, ":", result)); |
| 1746 | |
| 1747 | m_diffsBeingApplied.erase(countryId); |
| 1748 | switch (result) |
| 1749 | { |
| 1750 | case DiffApplicationResult::Ok: |
| 1751 | { |
| 1752 | RegisterCountryFiles(diffFile); |
| 1753 | m_diffsDataSource->MarkAsApplied(countryId); |
| 1754 | fn(true); |
| 1755 | break; |
| 1756 | } |
| 1757 | case DiffApplicationResult::Cancelled: |
| 1758 | { |
| 1759 | break; |
| 1760 | } |
| 1761 | case DiffApplicationResult::Failed: |
| 1762 | { |
nothing calls this directly
no test coverage detected