diff --git a/storage/storage.cpp b/storage/storage.cpp index e118174277..c212572e0e 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -262,7 +262,7 @@ void Storage::RegisterAllLocalMaps() LocalCountryFile const & localFile = *i; string const & name = localFile.GetCountryName(); TCountryId countryId = FindCountryIdByFile(name); - if (IsCountryIdValid(countryId) && IsCoutryIdInCountryTree(countryId)) + if (IsCoutryIdCountryTreeLeaf(countryId)) RegisterCountryFiles(countryId, localFile.GetDirectory(), localFile.GetVersion()); else RegisterFakeCountryFiles(localFile); @@ -306,9 +306,12 @@ Country const & Storage::CountryByCountryId(TCountryId const & countryId) const return node->Value(); } -bool Storage::IsCoutryIdInCountryTree(TCountryId const & countryId) const +bool Storage::IsCoutryIdCountryTreeLeaf(TCountryId const & countryId) const { - return m_countries.FindFirst(countryId) != nullptr; + if (!IsCountryIdValid(countryId)) + return false; + TCountryTreeNode const * const node = m_countries.FindFirst(countryId); + return node != nullptr && node->ChildrenCount() == 0 /* countryId is a leaf. */; } TLocalAndRemoteSize Storage::CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const @@ -342,7 +345,7 @@ Storage::TLocalFilePtr Storage::GetLatestLocalFile(CountryFile const & countryFi ASSERT_THREAD_CHECKER(m_threadChecker, ()); TCountryId const countryId = FindCountryIdByFile(countryFile.GetName()); - if (IsCountryIdValid(countryId) && IsCoutryIdInCountryTree(countryId)) + if (IsCoutryIdCountryTreeLeaf(countryId)) { TLocalFilePtr localFile = GetLatestLocalFile(countryId); if (localFile) @@ -493,7 +496,7 @@ void Storage::DeleteCustomCountryVersion(LocalCountryFile const & localFile) } TCountryId const countryId = FindCountryIdByFile(countryFile.GetName()); - if (!(IsCountryIdValid(countryId) && IsCoutryIdInCountryTree(countryId))) + if (!(IsCoutryIdCountryTreeLeaf(countryId))) { LOG(LERROR, ("Removed files for an unknown country:", localFile)); return; diff --git a/storage/storage.hpp b/storage/storage.hpp index 7b25cc0fb0..81239987da 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -416,7 +416,7 @@ public: TCountryId FindCountryIdByFile(string const & name) const; - bool IsCoutryIdInCountryTree(TCountryId const & countryId) const; + bool IsCoutryIdCountryTreeLeaf(TCountryId const & countryId) const; TLocalAndRemoteSize CountrySizeInBytes(TCountryId const & countryId, MapOptions opt) const; platform::CountryFile const & GetCountryFile(TCountryId const & countryId) const; diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 3c7f36f90a..9ff05c229f 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -229,7 +229,7 @@ public: m_slot = m_storage.Subscribe( bind(&CountryDownloaderChecker::OnCountryStatusChanged, this, _1), bind(&CountryDownloaderChecker::OnCountryDownloadingProgress, this, _1, _2)); - TEST(storage.IsCoutryIdInCountryTree(countryId), (m_countryFile)); + TEST(storage.IsCoutryIdCountryTreeLeaf(countryId), (m_countryFile)); TEST(!m_transitionList.empty(), (m_countryFile)); }