From 2dd63cac9b1573cef51853f49aa17f6007d00249 Mon Sep 17 00:00:00 2001 From: Yuri Gorshenin Date: Mon, 2 Nov 2015 12:49:02 +0300 Subject: [PATCH] [storage] Fixed downloading of an empty routing file. --- storage/storage.cpp | 10 ++++++++++ storage/storage_tests/storage_tests.cpp | 26 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/storage/storage.cpp b/storage/storage.cpp index dee802f990..769a31614e 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -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; } diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 6ee91c7017..baefeac4d2 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -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