MCPcopy Create free account
hub / github.com/comaps/comaps / OnDownloadFinished

Method OnDownloadFinished

libs/storage/storage.cpp:1012–1058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1010}
1011
1012void Storage::OnDownloadFinished(QueuedCountry const & queuedCountry, DownloadStatus status)
1013{
1014 CHECK_THREAD_CHECKER(m_threadChecker, ());
1015
1016 m_downloadingCountries.erase(queuedCountry.GetCountryId());
1017
1018 auto const & countryId = queuedCountry.GetCountryId();
1019 auto const fileType = queuedCountry.GetFileType();
1020 auto const finishFn = [this, countryId, fileType](DownloadStatus status)
1021 {
1022 OnMapDownloadFinished(countryId, status, fileType);
1023 OnFinishDownloading();
1024 };
1025
1026 if (status == DownloadStatus::Completed && m_integrityValidationEnabled)
1027 {
1028 /// @todo Can/Should be combined with ApplyDiff routine when we will restore it.
1029 /// While this is simple and working solution, I think that Downloader component
1030 /// should make this kind of checks (taking expecting SHA as input). But now it's
1031 /// not so simple as it may seem ..
1032
1033 GetPlatform().RunTask(Platform::Thread::File,
1034 [path = GetFileDownloadPath(countryId, fileType), sha1 = GetCountryFile(countryId).GetSha1(),
1035 fn = std::move(finishFn)]()
1036 {
1037 DownloadStatus status = DownloadStatus::Completed;
1038
1039 // Verify map checksum.
1040 if (coding::SHA1::CalculateBase64(path) != sha1)
1041 {
1042 LOG(LERROR, ("SHA check error for", path));
1043 base::DeleteFileX(path);
1044 status = DownloadStatus::FailedSHA;
1045 }
1046
1047 GetPlatform().RunTask(Platform::Thread::Gui, [fn = std::move(fn), status]()
1048 {
1049 if (status == DownloadStatus::Completed)
1050 LOG(LDEBUG, ("Successful SHA check"));
1051
1052 fn(status);
1053 });
1054 });
1055 }
1056 else
1057 finishFn(status);
1058}
1059
1060void Storage::RegisterDownloadedFiles(CountryId const & countryId, MapFileType type)
1061{

Callers 2

OnMapFileDownloadedMethod · 0.45
OnFileDownloadedMethod · 0.45

Calls 6

DeleteFileXFunction · 0.85
GetCountryIdMethod · 0.80
RunTaskMethod · 0.80
GetFileDownloadPathFunction · 0.50
eraseMethod · 0.45
GetFileTypeMethod · 0.45

Tested by

no test coverage detected