Merge pull request #429 from ygorshenin/fix-empty-routing-file-downloading

[storage] Fixed downloading of an empty routing file.
This commit is contained in:
Sergey Yershov 2015-11-02 13:34:59 +03:00
commit 662a1ee0c4
3 changed files with 49 additions and 13 deletions

View file

@ -719,31 +719,41 @@ TStatus Storage::CountryStatusFull(TIndex const & index, TStatus const status) c
return TStatus::EOnDisk;
}
MapOptions Storage::NormalizeDownloadFileSet(TIndex const & index, MapOptions opt) const
MapOptions Storage::NormalizeDownloadFileSet(TIndex const & index, MapOptions options) const
{
auto const & country = GetCountryFile(index);
// Car routing files are useless without map files.
if (HasOptions(opt, MapOptions::CarRouting))
opt = SetOptions(opt, MapOptions::Map);
if (HasOptions(options, MapOptions::CarRouting))
options = SetOptions(options, MapOptions::Map);
TLocalFilePtr localCountryFile = GetLatestLocalFile(index);
for (MapOptions file : {MapOptions::Map, MapOptions::CarRouting})
for (MapOptions option : {MapOptions::Map, MapOptions::CarRouting})
{
// Check whether requested files are on disk and up-to-date.
if (HasOptions(opt, file) && localCountryFile && localCountryFile->OnDisk(file) &&
if (HasOptions(options, option) && localCountryFile && localCountryFile->OnDisk(option) &&
localCountryFile->GetVersion() == GetCurrentDataVersion())
{
opt = UnsetOptions(opt, file);
options = UnsetOptions(options, option);
}
// Check whether requested file is not empty.
if (GetRemoteSize(country, option) == 0)
{
ASSERT_NOT_EQUAL(MapOptions::Map, option, ("Map can't be empty."));
options = UnsetOptions(options, option);
}
}
return opt;
return options;
}
MapOptions Storage::NormalizeDeleteFileSet(MapOptions opt) const
MapOptions Storage::NormalizeDeleteFileSet(MapOptions options) const
{
// Car routing files are useless without map files.
if (HasOptions(opt, MapOptions::Map))
opt = SetOptions(opt, MapOptions::CarRouting);
return opt;
if (HasOptions(options, MapOptions::Map))
options = SetOptions(options, MapOptions::CarRouting);
return options;
}
QueuedCountry * Storage::FindCountryInQueue(TIndex const & index)

View file

@ -190,11 +190,11 @@ private:
// Modifies file set of requested files - always adds a map file
// when routing file is requested for downloading, but drops all
// already downloaded and up-to-date files.
MapOptions NormalizeDownloadFileSet(TIndex const & index, MapOptions opt) const;
MapOptions NormalizeDownloadFileSet(TIndex const & index, MapOptions options) const;
// Modifies file set of file to deletion - always adds (marks for
// removal) a routing file when map file is marked for deletion.
MapOptions NormalizeDeleteFileSet(MapOptions opt) const;
MapOptions NormalizeDeleteFileSet(MapOptions options) const;
// Returns a pointer to a country in the downloader's queue.
QueuedCountry * FindCountryInQueue(TIndex const & index);

View file

@ -706,4 +706,30 @@ UNIT_TEST(StorageTest_FailedDownloading)
TEST(Platform::IsFileExistsByFullPath(downloadPath + DOWNLOADING_FILE_EXTENSION), ());
TEST(Platform::IsFileExistsByFullPath(downloadPath + RESUME_FILE_EXTENSION), ());
}
// "South Georgia and the South Sandwich" doesn't have roads, so there
// is no routing file for this island.
UNIT_TEST(StorageTest_EmptyRoutingFile)
{
Storage storage;
TaskRunner runner;
InitStorage(storage, runner, [](LocalCountryFile const & localFile)
{
TEST_EQUAL(localFile.GetFiles(), MapOptions::Map, ());
});
TIndex const index = storage.FindIndexByFile("South Georgia and the South Sandwich Islands");
TEST(index.IsValid(), ());
storage.DeleteCountry(index, MapOptions::MapWithCarRouting);
MY_SCOPE_GUARD(cleanup,
bind(&Storage::DeleteCountry, &storage, index, MapOptions::MapWithCarRouting));
CountryFile const country = storage.GetCountryFile(index);
TEST_NOT_EQUAL(country.GetRemoteSize(MapOptions::Map), 0, ());
TEST_EQUAL(country.GetRemoteSize(MapOptions::CarRouting), 0, ());
auto checker = AbsentCountryDownloaderChecker(storage, index, MapOptions::MapWithCarRouting);
checker->StartDownload();
runner.Run();
}
} // namespace storage