[platform] LocalCountryFile::GetFiles is removed

This commit is contained in:
Arsentiy Milchakov 2019-09-26 17:52:58 +03:00 committed by mpimenov
parent 9587218d28
commit 9fd65dac7a
9 changed files with 48 additions and 37 deletions

View file

@ -59,7 +59,7 @@ int main(int argc, char * argv[])
for (auto & file : localFiles)
{
file.SyncWithDisk();
if (file.GetFiles() != MapOptions::MapWithCarRouting)
if (!file.OnDisk(MapOptions::MapWithCarRouting))
{
LOG(LINFO, ("Warning! Routing file not found for:", file.GetCountryName()));
continue;

View file

@ -23,9 +23,8 @@ SingleMwmDataSource::SingleMwmDataSource(std::string const & mwmPath)
{
m_countryFile = platform::LocalCountryFile::MakeTemporary(mwmPath);
m_countryFile.SyncWithDisk();
CHECK_EQUAL(
m_countryFile.GetFiles(), MapOptions::MapWithCarRouting,
("No correct mwm corresponding to local country file:", m_countryFile, ". Path:", mwmPath));
CHECK(m_countryFile.OnDisk(MapOptions::MapWithCarRouting),
("No correct mwm corresponding to local country file:", m_countryFile, ". Path:", mwmPath));
auto const result = m_dataSource.Register(m_countryFile);
CHECK_EQUAL(result.second, MwmSet::RegResult::Success, ());

View file

@ -676,7 +676,7 @@ void Framework::OnCountryFileDownloaded(storage::CountryId const & countryId,
m2::RectD rect = MercatorBounds::FullRect();
if (localFile && HasOptions(localFile->GetFiles(), MapOptions::Map))
if (localFile && localFile->OnDisk(MapOptions::Map))
{
// Add downloaded map.
auto p = m_featuresFetcher.RegisterMap(*localFile);

View file

@ -15,8 +15,16 @@ using namespace std;
namespace platform
{
namespace
{
void SetOptions(boost::optional<MapOptions> & destination, MapOptions value)
{
destination = destination ? SetOptions(destination.get(), value) : value;
}
} // namespace
LocalCountryFile::LocalCountryFile()
: m_version(0), m_files(MapOptions::Nothing), m_mapSize(0), m_routingSize(0)
: m_version(0), m_mapSize(0), m_routingSize(0)
{
}
@ -25,7 +33,6 @@ LocalCountryFile::LocalCountryFile(string const & directory, CountryFile const &
: m_directory(directory),
m_countryFile(countryFile),
m_version(version),
m_files(MapOptions::Nothing),
m_mapSize(0),
m_routingSize(0)
{
@ -33,30 +40,30 @@ LocalCountryFile::LocalCountryFile(string const & directory, CountryFile const &
void LocalCountryFile::SyncWithDisk()
{
m_files = MapOptions::Nothing;
m_files = {};
m_mapSize = 0;
m_routingSize = 0;
Platform & platform = GetPlatform();
if (platform.GetFileSizeByFullPath(GetPath(MapOptions::Diff), m_mapSize))
{
m_files = SetOptions(m_files, MapOptions::Diff);
SetOptions(m_files, MapOptions::Diff);
return;
}
if (platform.GetFileSizeByFullPath(GetPath(MapOptions::Map), m_mapSize))
m_files = SetOptions(m_files, MapOptions::Map);
SetOptions(m_files, MapOptions::Map);
if (version::IsSingleMwm(GetVersion()))
{
if (m_files == MapOptions::Map)
m_files = SetOptions(m_files, MapOptions::CarRouting);
SetOptions(m_files, MapOptions::CarRouting);
return;
}
string const routingPath = GetPath(MapOptions::CarRouting);
if (platform.GetFileSizeByFullPath(routingPath, m_routingSize))
m_files = SetOptions(m_files, MapOptions::CarRouting);
SetOptions(m_files, MapOptions::CarRouting);
}
void LocalCountryFile::DeleteFromDisk(MapOptions files) const
@ -140,7 +147,7 @@ string DebugPrint(LocalCountryFile const & file)
{
ostringstream os;
os << "LocalCountryFile [" << file.m_directory << ", " << DebugPrint(file.m_countryFile) << ", "
<< file.m_version << ", " << DebugPrint(file.m_files) << "]";
<< file.m_version << ", " << (file.m_files ? DebugPrint(file.m_files.get()) : "No files") << "]";
return os.str();
}
} // namespace platform

View file

@ -7,6 +7,8 @@
#include <string>
#include <vector>
#include <boost/optional.hpp>
namespace platform
{
// This class represents a path to disk files corresponding to some
@ -55,15 +57,18 @@ public:
// SyncWithDisk() is called.
uint64_t GetSize(MapOptions filesMask) const;
// Returns a mask of all known country files. Return value may be
// empty until SyncWithDisk() is called.
MapOptions GetFiles() const { return m_files; }
// Returns true when some files are found during SyncWithDisk.
// Return value may be empty until SyncWithDisk() is called.
bool HasFiles() const { return m_files.is_initialized(); }
// Checks whether files specified in filesMask are on disk. Return
// value will be false until SyncWithDisk() is called.
bool OnDisk(MapOptions filesMask) const
{
return (static_cast<unsigned>(m_files) & static_cast<unsigned>(filesMask)) ==
if (!m_files)
return false;
return (static_cast<unsigned>(m_files.get()) & static_cast<unsigned>(filesMask)) ==
static_cast<unsigned>(filesMask);
}
@ -100,7 +105,7 @@ private:
CountryFile m_countryFile;
int64_t m_version;
MapOptions m_files;
boost::optional<MapOptions> m_files;
/// Size of file which contains map section in bytes. It's mwm file in any case.
uint64_t m_mapSize;

View file

@ -77,12 +77,10 @@ UNIT_TEST(LocalCountryFile_Smoke)
localFile.GetPath(MapOptions::CarRouting), ());
// Not synced with disk yet.
TEST_EQUAL(MapOptions::Nothing, localFile.GetFiles(), ());
// Any statement is true about elements of an empty set.
TEST(localFile.OnDisk(MapOptions::Nothing), ());
TEST(!localFile.HasFiles(), ());
TEST(!localFile.OnDisk(MapOptions::Map), ());
TEST(!localFile.OnDisk(MapOptions::Diff), ());
TEST(!localFile.OnDisk(MapOptions::CarRouting), ());
TEST(!localFile.OnDisk(MapOptions::MapWithCarRouting), ());
@ -186,7 +184,7 @@ UNIT_TEST(LocalCountryFile_CleanupMapFiles)
brazilMapFile.Reset();
irelandLocalFile.SyncWithDisk();
TEST_EQUAL(MapOptions::Map, irelandLocalFile.GetFiles(), ());
TEST(irelandLocalFile.OnDisk(MapOptions::Map), ());
irelandLocalFile.DeleteFromDisk(MapOptions::Map);
TEST(!irelandMapFile.Exists(), (irelandMapFile));
irelandMapFile.Reset();

View file

@ -49,7 +49,7 @@ void TestAltitudeOfAllMwmFeatures(string const & countryId, TAltitude const alti
LocalCountryFile const country = GetLocalCountryFileByCountryId(CountryFile(countryId));
TEST_NOT_EQUAL(country, LocalCountryFile(), ());
TEST_NOT_EQUAL(country.GetFiles(), MapOptions::Nothing, (country));
TEST(country.HasFiles(), (country));
pair<MwmSet::MwmId, MwmSet::RegResult> const regResult = dataSource.RegisterMap(country);
TEST_EQUAL(regResult.second, MwmSet::RegResult::Success, ());

View file

@ -1220,7 +1220,7 @@ void Storage::DeleteCountryFiles(CountryId const & countryId, MapOptions opt, bo
{
DeleteFromDiskWithIndexes(*localFile, opt);
localFile->SyncWithDisk();
if (localFile->GetFiles() == MapOptions::Nothing)
if (!localFile->HasFiles())
localFile.reset();
}
auto isNull = [](LocalFilePtr const & localFile) { return !localFile; };

View file

@ -49,6 +49,8 @@
#include <mutex>
#include <vector>
#include <boost/optional.hpp>
#include "defines.hpp"
using namespace platform::tests_support;
@ -543,7 +545,7 @@ LocalFilePtr CreateDummyMapFile(CountryFile const & countryFile, int64_t version
writer.Write(zeroes.data(), zeroes.size());
}
localFile->SyncWithDisk();
TEST_EQUAL(MapOptions::Map, localFile->GetFiles(), ());
TEST(localFile->OnDisk(MapOptions::Map), ());
TEST_EQUAL(size, localFile->GetSize(MapOptions::Map), ());
return localFile;
}
@ -697,10 +699,10 @@ UNIT_TEST(StorageTest_DeleteTwoVersionsOfTheSameCountry)
storage.DeleteCountry(countryId, MapOptions::Map);
localFileV1->SyncWithDisk();
TEST_EQUAL(MapOptions::Nothing, localFileV1->GetFiles(), ());
TEST(!localFileV1->HasFiles(), ());
localFileV2->SyncWithDisk();
TEST_EQUAL(MapOptions::Nothing, localFileV2->GetFiles(), ());
TEST(!localFileV1->HasFiles(), ());
TEST_EQUAL(Status::ENotDownloaded, storage.CountryStatusEx(countryId), ());
}
@ -742,11 +744,11 @@ UNIT_TEST(StorageTest_DownloadMapAndRoutingSeparately)
LocalFilePtr localFileA = storage.GetLatestLocalFile(countryId);
TEST(localFileA.get(), ());
TEST_EQUAL(MapOptions::Map, localFileA->GetFiles(), ());
TEST(localFileA->OnDisk(MapOptions::Map), ());
MwmSet::MwmId id = mwmSet.GetMwmIdByCountryFile(countryFile);
TEST(id.IsAlive(), ());
TEST_EQUAL(MapOptions::Map, id.GetInfo()->GetLocalFile().GetFiles(), ());
TEST(id.GetInfo()->GetLocalFile().OnDisk(MapOptions::Map), ());
// Download routing file in addition to exising map file.
{
@ -759,10 +761,10 @@ UNIT_TEST(StorageTest_DownloadMapAndRoutingSeparately)
LocalFilePtr localFileB = storage.GetLatestLocalFile(countryId);
TEST(localFileB.get(), ());
TEST_EQUAL(localFileA.get(), localFileB.get(), (*localFileA, *localFileB));
TEST_EQUAL(MapOptions::MapWithCarRouting, localFileB->GetFiles(), ());
TEST(localFileB->OnDisk(MapOptions::MapWithCarRouting), ());
TEST(id.IsAlive(), ());
TEST_EQUAL(MapOptions::MapWithCarRouting, id.GetInfo()->GetLocalFile().GetFiles(), ());
TEST(id.GetInfo()->GetLocalFile().OnDisk(MapOptions::MapWithCarRouting), ());
// Delete routing file and check status update.
{
@ -772,10 +774,10 @@ UNIT_TEST(StorageTest_DownloadMapAndRoutingSeparately)
LocalFilePtr localFileC = storage.GetLatestLocalFile(countryId);
TEST(localFileC.get(), ());
TEST_EQUAL(localFileB.get(), localFileC.get(), (*localFileB, *localFileC));
TEST_EQUAL(MapOptions::Map, localFileC->GetFiles(), ());
TEST(localFileC->OnDisk(MapOptions::Map), ());
TEST(id.IsAlive(), ());
TEST_EQUAL(MapOptions::Map, id.GetInfo()->GetLocalFile().GetFiles(), ());
TEST(id.GetInfo()->GetLocalFile().OnDisk(MapOptions::Map), ());
// Delete map file and check status update.
{
@ -786,7 +788,7 @@ UNIT_TEST(StorageTest_DownloadMapAndRoutingSeparately)
// Framework should notify MwmSet about deletion of a map file.
// As there're no framework, there should not be any changes in MwmInfo.
TEST(id.IsAlive(), ());
TEST_EQUAL(MapOptions::Map, id.GetInfo()->GetLocalFile().GetFiles(), ());
TEST(id.GetInfo()->GetLocalFile().OnDisk(MapOptions::Map), ());
}
UNIT_CLASS_TEST(StorageTest, DeletePendingCountry)
@ -921,7 +923,7 @@ UNIT_CLASS_TEST(StorageTest, DeleteCountry)
tests_support::ScopedFile map("Wonderland.mwm", ScopedFile::Mode::Create);
LocalCountryFile file = LocalCountryFile::MakeForTesting("Wonderland",
version::FOR_TESTING_SINGLE_MWM1);
TEST_EQUAL(MapOptions::MapWithCarRouting, file.GetFiles(), ());
TEST(file.OnDisk(MapOptions::MapWithCarRouting), ());
CountryIndexes::PreparePlaceOnDisk(file);
string const bitsPath = CountryIndexes::GetPath(file, CountryIndexes::Index::Bits);
@ -947,7 +949,7 @@ UNIT_CLASS_TEST(TwoComponentStorageTest, DeleteCountry)
tests_support::ScopedFile map("Wonderland.mwm", ScopedFile::Mode::Create);
LocalCountryFile file = LocalCountryFile::MakeForTesting("Wonderland",
version::FOR_TESTING_TWO_COMPONENT_MWM1);
TEST_EQUAL(MapOptions::Map, file.GetFiles(), ());
TEST(file.OnDisk(MapOptions::Map), ());
CountryIndexes::PreparePlaceOnDisk(file);
string const bitsPath = CountryIndexes::GetPath(file, CountryIndexes::Index::Bits);