From cece22ef9c87d34cd6d12b4be14e2f3b44151bf6 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Thu, 26 Sep 2019 11:35:31 +0300 Subject: [PATCH] [ugc] Fix UGC_IndexMigrationFromV0ToV1Smoke test. --- ugc/storage.cpp | 28 +++++++++++++++++++--------- ugc/storage.hpp | 3 +++ ugc/ugc_tests/storage_tests.cpp | 15 +++++++++++---- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/ugc/storage.cpp b/ugc/storage.cpp index e4ea8905b2..1638f07551 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -33,6 +33,7 @@ #include using namespace std; +using namespace ugc; namespace { @@ -42,15 +43,11 @@ string const kTmpFileExtension = ".tmp"; using Sink = MemWriter; -string GetUGCFilePath() { return base::JoinPath(GetPlatform().SettingsDir(), kUGCUpdateFileName); } - -string GetIndexFilePath() { return base::JoinPath(GetPlatform().SettingsDir(), kIndexFileName); } - bool GetUGCFileSize(uint64_t & size) { try { - FileReader reader(GetUGCFilePath()); + FileReader reader(Storage::GetUGCFilePath()); size = reader.Size(); } catch (FileReader::Exception const &) @@ -138,7 +135,8 @@ bool SaveIndexes(ugc::UpdateIndexes const & indexes, std::string const & pathToT if (indexes.empty()) return false; - auto const indexFilePath = pathToTargetFile.empty() ? GetIndexFilePath() : pathToTargetFile; + auto const indexFilePath = + pathToTargetFile.empty() ? Storage::GetIndexFilePath() : pathToTargetFile; auto const jsonData = SerializeIndexes(indexes); try { @@ -197,7 +195,7 @@ ugc::Storage::SettingResult SetGenericUGCUpdate(UGCUpdate const & ugc, index.m_offset = offset; index.m_version = ugc::IndexVersion::Latest; - auto const ugcFilePath = GetUGCFilePath(); + auto const ugcFilePath = Storage::GetUGCFilePath(); try { FileWriter w(ugcFilePath, FileWriter::Op::OP_APPEND); @@ -217,7 +215,7 @@ ugc::Storage::SettingResult SetGenericUGCUpdate(UGCUpdate const & ugc, void FindZombieObjects(size_t indexesCount) { - auto const ugcFilePath = GetUGCFilePath(); + auto const ugcFilePath = Storage::GetUGCFilePath(); vector ugcFileContent; try { @@ -265,6 +263,18 @@ void FindZombieObjects(size_t indexesCount) namespace ugc { +// static +string Storage::GetUGCFilePath() +{ + return base::JoinPath(GetPlatform().SettingsDir(), kUGCUpdateFileName); +} + +// static +string Storage::GetIndexFilePath() +{ + return base::JoinPath(GetPlatform().SettingsDir(), kIndexFileName); +} + UGCUpdate Storage::GetUGCUpdate(FeatureID const & id) const { if (m_indexes.empty()) @@ -649,7 +659,7 @@ namespace impl { size_t GetNumberOfUnsentUGC() { - auto const indexFilePath = GetIndexFilePath(); + auto const indexFilePath = Storage::GetIndexFilePath(); if (!Platform::IsFileExistsByFullPath(indexFilePath)) return 0; diff --git a/ugc/storage.hpp b/ugc/storage.hpp index 0d89e46567..2c25a4418e 100644 --- a/ugc/storage.hpp +++ b/ugc/storage.hpp @@ -25,6 +25,9 @@ class Storage public: explicit Storage(DataSource const & dataSource) : m_dataSource(dataSource) {} + static std::string GetUGCFilePath(); + static std::string GetIndexFilePath(); + UGCUpdate GetUGCUpdate(FeatureID const & id) const; enum class SettingResult diff --git a/ugc/ugc_tests/storage_tests.cpp b/ugc/ugc_tests/storage_tests.cpp index f460a18945..824700ab7e 100644 --- a/ugc/ugc_tests/storage_tests.cpp +++ b/ugc/ugc_tests/storage_tests.cpp @@ -19,16 +19,17 @@ #include "platform/local_country_file_utils.hpp" #include "platform/platform.hpp" -#include "platform/platform_tests_support/scoped_file.hpp" #include "coding/internal/file_data.hpp" #include "coding/writer.hpp" #include "coding/zlib.hpp" #include "base/file_name_utils.hpp" +#include "base/scope_guard.hpp" #include #include +#include #include #include #include @@ -48,7 +49,7 @@ string const kTestMwmName = "ugc storage test"; bool DeleteIndexFile(ugc::IndexVersion v = ugc::IndexVersion::Latest) { if (v == ugc::IndexVersion::Latest) - return base::DeleteFileX(base::JoinPath(GetPlatform().SettingsDir(), "index.json")); + return base::DeleteFileX(Storage::GetIndexFilePath()); string version; switch (v) @@ -61,7 +62,7 @@ bool DeleteIndexFile(ugc::IndexVersion v = ugc::IndexVersion::Latest) break; } - return base::DeleteFileX(base::JoinPath(GetPlatform().SettingsDir(), "index.json." + version)); + return base::DeleteFileX(Storage::GetIndexFilePath() + "." + version); } bool DeleteUGCFile(ugc::IndexVersion v = ugc::IndexVersion::Latest) @@ -463,7 +464,13 @@ UNIT_CLASS_TEST(StorageTest, GetNumberOfUnsentSeparately) UNIT_TEST(UGC_IndexMigrationFromV0ToV1Smoke) { - platform::tests_support::ScopedFile dummyUgcUpdate("ugc.update.bin", "some test content"); + auto const dummyUgcUpdate = Storage::GetUGCFilePath(); + SCOPE_GUARD(deleteFileGuard, bind(&FileWriter::DeleteFileX, cref(dummyUgcUpdate))); + { + ofstream stream; + stream.open(dummyUgcUpdate); + stream << "some test content"; + } LOG(LINFO, ("Created dummy ugc update", dummyUgcUpdate)); auto & p = GetPlatform();