[storage] Fixed downloading of an empty routing file.

This commit is contained in:
Yuri Gorshenin 2015-11-02 12:49:02 +03:00
parent 9ead4362ea
commit 2dd63cac9b
2 changed files with 36 additions and 0 deletions

View file

@ -721,6 +721,8 @@ TStatus Storage::CountryStatusFull(TIndex const & index, TStatus const status) c
MapOptions Storage::NormalizeDownloadFileSet(TIndex const & index, MapOptions opt) const
{
auto const & country = GetCountryFile(index);
// Car routing files are useless without map files.
if (HasOptions(opt, MapOptions::CarRouting))
opt = SetOptions(opt, MapOptions::Map);
@ -734,7 +736,15 @@ MapOptions Storage::NormalizeDownloadFileSet(TIndex const & index, MapOptions op
{
opt = UnsetOptions(opt, file);
}
// Check whether requested file is not empty.
if (GetRemoteSize(country, file) == 0)
{
ASSERT_NOT_EQUAL(MapOptions::Map, file, ("Map can't be empty."));
opt = UnsetOptions(opt, file);
}
}
return opt;
}

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