diff options
author | Maxim Pimenov <m@maps.me> | 2019-03-14 12:01:37 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2019-03-18 18:42:54 +0300 |
commit | 558dc877923ff745d6b13c41b151bdebea66836a (patch) | |
tree | 00880b06a5fc1fc4c6dc3ad0667977de122c4503 /platform | |
parent | a95e858c6ecbd90d80ed5cffcdb124d915835e61 (diff) |
[platform] Using JoinPath instead of JoinFoldersToPath.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/get_text_by_id.cpp | 4 | ||||
-rw-r--r-- | platform/local_country_file.cpp | 2 | ||||
-rw-r--r-- | platform/local_country_file_utils.cpp | 27 | ||||
-rw-r--r-- | platform/platform.cpp | 4 | ||||
-rw-r--r-- | platform/platform_linux.cpp | 8 | ||||
-rw-r--r-- | platform/platform_tests/local_country_file_tests.cpp | 11 | ||||
-rw-r--r-- | platform/platform_tests/platform_test.cpp | 14 | ||||
-rw-r--r-- | platform/platform_tests_support/scoped_dir.cpp | 8 | ||||
-rw-r--r-- | platform/platform_tests_support/scoped_file.cpp | 2 |
9 files changed, 41 insertions, 39 deletions
diff --git a/platform/get_text_by_id.cpp b/platform/get_text_by_id.cpp index 4d5e44053c..4af9031aec 100644 --- a/platform/get_text_by_id.cpp +++ b/platform/get_text_by_id.cpp @@ -34,8 +34,8 @@ namespace platform { bool GetJsonBuffer(platform::TextSource textSource, string const & localeName, string & jsonBuffer) { - string const pathToJson = base::JoinFoldersToPath( - {GetTextSourceString(textSource), localeName + ".json"}, "localize.json"); + string const pathToJson = + base::JoinPath(GetTextSourceString(textSource), localeName + ".json", "localize.json"); try { diff --git a/platform/local_country_file.cpp b/platform/local_country_file.cpp index 4dca8371b8..b806e5f13e 100644 --- a/platform/local_country_file.cpp +++ b/platform/local_country_file.cpp @@ -74,7 +74,7 @@ void LocalCountryFile::DeleteFromDisk(MapOptions files) const string LocalCountryFile::GetPath(MapOptions file) const { - return base::JoinFoldersToPath(m_directory, GetFileName(m_countryFile.GetName(), file, GetVersion())); + return base::JoinPath(m_directory, GetFileName(m_countryFile.GetName(), file, GetVersion())); } uint64_t LocalCountryFile::GetSize(MapOptions filesMask) const diff --git a/platform/local_country_file_utils.cpp b/platform/local_country_file_utils.cpp index 67c8a9aade..f768144294 100644 --- a/platform/local_country_file_utils.cpp +++ b/platform/local_country_file_utils.cpp @@ -100,8 +100,7 @@ bool DirectoryHasIndexesOnly(string const & directory) inline string GetDataDirFullPath(string const & dataDir) { Platform & platform = GetPlatform(); - return dataDir.empty() ? platform.WritableDir() - : base::JoinFoldersToPath(platform.WritableDir(), dataDir); + return dataDir.empty() ? platform.WritableDir() : base::JoinPath(platform.WritableDir(), dataDir); } void FindAllDiffsInDirectory(string const & dir, vector<LocalCountryFile> & diffs) @@ -139,8 +138,8 @@ string GetFilePath(int64_t version, string const & dataDir, CountryFile const & string const filename = GetFileName(countryFile.GetName(), options, version); string const dir = GetDataDirFullPath(dataDir); if (version == 0) - return base::JoinFoldersToPath(dir, filename); - return base::JoinFoldersToPath({dir, strings::to_string(version)}, filename); + return base::JoinPath(dir, filename); + return base::JoinPath(dir, strings::to_string(version), filename); } } // namespace @@ -189,7 +188,7 @@ void FindAllLocalMapsInDirectoryAndCleanup(string const & directory, int64_t ver // Remove downloader and diff files for old version directories. if (version < latestVersion && (IsDownloaderFile(name) || IsDiffFile(name))) { - base::DeleteFileX(base::JoinFoldersToPath(directory, name)); + base::DeleteFileX(base::JoinPath(directory, name)); continue; } @@ -223,7 +222,7 @@ void FindAllLocalMapsInDirectoryAndCleanup(string const & directory, int64_t ver if (IsSpecialName(name)) continue; - if (names.count(name) == 0 && DirectoryHasIndexesOnly(base::JoinFoldersToPath(directory, name))) + if (names.count(name) == 0 && DirectoryHasIndexesOnly(base::JoinPath(directory, name))) { // Directory which looks like a directory with indexes for absent country. It's OK to remove // it. @@ -242,7 +241,7 @@ void FindAllDiffs(string const & dataDir, vector<LocalCountryFile> & diffs) Platform::GetFilesByType(dir, Platform::FILE_TYPE_DIRECTORY, fwts); for (auto const & fwt : fwts) - FindAllDiffsInDirectory(base::JoinFoldersToPath(dir, fwt.first /* subdir */), diffs); + FindAllDiffsInDirectory(base::JoinPath(dir, fwt.first /* subdir */), diffs); } void FindAllLocalMapsAndCleanup(int64_t latestVersion, vector<LocalCountryFile> & localFiles) @@ -265,7 +264,7 @@ void FindAllLocalMapsAndCleanup(int64_t latestVersion, string const & dataDir, if (!ParseVersion(subdir, version) || version > latestVersion) continue; - string const fullPath = base::JoinFoldersToPath(dir, subdir); + string const fullPath = base::JoinPath(dir, subdir); FindAllLocalMapsInDirectoryAndCleanup(fullPath, version, latestVersion, localFiles); Platform::EError err = Platform::RmDir(fullPath); if (err != Platform::ERR_OK && err != Platform::ERR_DIRECTORY_NOT_EMPTY) @@ -348,7 +347,7 @@ shared_ptr<LocalCountryFile> PreparePlaceForCountryFiles(int64_t version, string string const dir = GetDataDirFullPath(dataDir); if (version == 0) return make_shared<LocalCountryFile>(dir, countryFile, version); - string const directory = base::JoinFoldersToPath(dir, strings::to_string(version)); + string const directory = base::JoinPath(dir, strings::to_string(version)); if (!Platform::MkDirChecked(directory)) return shared_ptr<LocalCountryFile>(); return make_shared<LocalCountryFile>(directory, countryFile, version); @@ -366,8 +365,8 @@ string GetFileDownloadPath(int64_t version, string const & dataDir, CountryFile GetFileName(countryFile.GetName(), options, version) + READY_FILE_EXTENSION; string const dir = GetDataDirFullPath(dataDir); if (version == 0) - return base::JoinFoldersToPath(dir, readyFile); - return base::JoinFoldersToPath({dir, strings::to_string(version)}, readyFile); + return base::JoinPath(dir, readyFile); + return base::JoinPath(dir, strings::to_string(version), readyFile); } unique_ptr<ModelReader> GetCountryReader(platform::LocalCountryFile const & file, @@ -426,7 +425,7 @@ string CountryIndexes::GetPath(LocalCountryFile const & localFile, Index index) case Index::Nodes: ext = kNodesExt; break; case Index::Offsets: ext = kOffsetsExt; break; } - return base::JoinFoldersToPath(IndexesDir(localFile), localFile.GetCountryName() + ext); + return base::JoinPath(IndexesDir(localFile), localFile.GetCountryName() + ext); } // static @@ -458,12 +457,12 @@ string CountryIndexes::IndexesDir(LocalCountryFile const & localFile) int64_t const version = localFile.GetVersion(); ASSERT_GREATER(version, 0, ()); - dir = base::JoinFoldersToPath(GetPlatform().WritableDir(), strings::to_string(version)); + dir = base::JoinPath(GetPlatform().WritableDir(), strings::to_string(version)); if (!Platform::MkDirChecked(dir)) MYTHROW(FileSystemException, ("Can't create directory", dir)); } - return base::JoinFoldersToPath(dir, file.GetName()); + return base::JoinPath(dir, file.GetName()); } string DebugPrint(CountryIndexes::Index index) diff --git a/platform/platform.cpp b/platform/platform.cpp index 1ef6edaf48..2559735a92 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -95,7 +95,7 @@ bool Platform::RmDirRecursively(string const & dirName) GetFilesByRegExp(dirName, ".*", allFiles); for (string const & file : allFiles) { - string const path = base::JoinFoldersToPath(dirName, file); + string const path = base::JoinPath(dirName, file); EFileType type; if (GetFileType(path, type) != ERR_OK) @@ -215,7 +215,7 @@ void Platform::GetFilesByType(string const & directory, unsigned typeMask, for (string const & file : allFiles) { EFileType type; - if (GetFileType(base::JoinFoldersToPath(directory, file), type) != ERR_OK) + if (GetFileType(base::JoinPath(directory, file), type) != ERR_OK) continue; if (typeMask & type) outFiles.emplace_back(file, type); diff --git a/platform/platform_linux.cpp b/platform/platform_linux.cpp index 8a0a1306b0..46c1b3bf89 100644 --- a/platform/platform_linux.cpp +++ b/platform/platform_linux.cpp @@ -96,8 +96,12 @@ string HomeDir() // An exception is thrown if the default dir is not already there and we were unable to create it. string DefaultWritableDir() { - initializer_list<string> dirs = {".local", "share", "MapsWithMe"}; - auto const result = base::JoinFoldersToPath(dirs, "" /* file */); + initializer_list<string> const dirs = {".local", "share", "MapsWithMe"}; + string result; + for (auto const & dir : dirs) + result = base::JoinPath(result, dir); + result = base::AddSlashIfNeeded(result); + auto const home = HomeDir(); if (!MkDirsChecked(home, dirs)) MYTHROW(FileSystemException, ("Cannot create directory:", result)); diff --git a/platform/platform_tests/local_country_file_tests.cpp b/platform/platform_tests/local_country_file_tests.cpp index f32dffb62c..16b5100b80 100644 --- a/platform/platform_tests/local_country_file_tests.cpp +++ b/platform/platform_tests/local_country_file_tests.cpp @@ -212,13 +212,13 @@ UNIT_TEST(LocalCountryFile_CleanupPartiallyDownloadedFiles) {"Netherlands.mwm.routing.downloading2", ScopedFile::Mode::Create}, {"Germany.mwm.ready3", ScopedFile::Mode::Create}, {"UK_England.mwm.resume4", ScopedFile::Mode::Create}, - {base::JoinFoldersToPath(oldDir.GetRelativePath(), "Russia_Central.mwm.downloading"), + {base::JoinPath(oldDir.GetRelativePath(), "Russia_Central.mwm.downloading"), ScopedFile::Mode::Create}}; ScopedFile toBeKept[] = { {"Italy.mwm", ScopedFile::Mode::Create}, {"Spain.mwm", ScopedFile::Mode::Create}, {"Spain.mwm.routing", ScopedFile::Mode::Create}, - {base::JoinFoldersToPath(latestDir.GetRelativePath(), "Russia_Southern.mwm.downloading"), + {base::JoinPath(latestDir.GetRelativePath(), "Russia_Southern.mwm.downloading"), ScopedFile::Mode::Create}}; CleanupMapsDirectory(101010 /* latestVersion */); @@ -347,9 +347,8 @@ UNIT_TEST(LocalCountryFile_CountryIndexes) CountryFile germanyFile("Germany"); LocalCountryFile germanyLocalFile(testDir.GetFullPath(), germanyFile, 101010 /* version */); - TEST_EQUAL( - base::JoinFoldersToPath(germanyLocalFile.GetDirectory(), germanyFile.GetName()), - CountryIndexes::IndexesDir(germanyLocalFile), ()); + TEST_EQUAL(base::JoinPath(germanyLocalFile.GetDirectory(), germanyFile.GetName()), + CountryIndexes::IndexesDir(germanyLocalFile), ()); CountryIndexes::PreparePlaceOnDisk(germanyLocalFile); string const bitsPath = CountryIndexes::GetPath(germanyLocalFile, CountryIndexes::Index::Bits); @@ -378,7 +377,7 @@ UNIT_TEST(LocalCountryFile_DoNotDeleteUserFiles) CountryIndexes::PreparePlaceOnDisk(germanyLocalFile); string const userFilePath = - base::JoinFoldersToPath(CountryIndexes::IndexesDir(germanyLocalFile), "user-data.txt"); + base::JoinPath(CountryIndexes::IndexesDir(germanyLocalFile), "user-data.txt"); { FileWriter writer(userFilePath); string const data = "user data"; diff --git a/platform/platform_tests/platform_test.cpp b/platform/platform_tests/platform_test.cpp index 3598434981..514110f899 100644 --- a/platform/platform_tests/platform_test.cpp +++ b/platform/platform_tests/platform_test.cpp @@ -110,8 +110,8 @@ UNIT_TEST(GetFilesInDir_Smoke) UNIT_TEST(DirsRoutines) { string const baseDir = GetPlatform().WritableDir(); - string const testDir = base::JoinFoldersToPath(baseDir, "test-dir"); - string const testFile = base::JoinFoldersToPath(testDir, "test-file"); + string const testDir = base::JoinPath(baseDir, "test-dir"); + string const testFile = base::JoinPath(testDir, "test-file"); TEST(!Platform::IsFileExistsByFullPath(testDir), ()); TEST_EQUAL(Platform::MkDir(testDir), Platform::ERR_OK, ()); @@ -137,11 +137,11 @@ UNIT_TEST(GetFilesByType) string const baseDir = GetPlatform().WritableDir(); - string const testDir = base::JoinFoldersToPath(baseDir, kTestDirBaseName); + string const testDir = base::JoinPath(baseDir, kTestDirBaseName); TEST_EQUAL(Platform::MkDir(testDir), Platform::ERR_OK, ()); SCOPE_GUARD(removeTestDir, bind(&Platform::RmDir, testDir)); - string const testFile = base::JoinFoldersToPath(baseDir, kTestFileBaseName); + string const testFile = base::JoinPath(baseDir, kTestFileBaseName); TEST(!Platform::IsFileExistsByFullPath(testFile), ()); { FileWriter writer(testFile); @@ -216,15 +216,15 @@ UNIT_TEST(GetWritableStorageStatus) UNIT_TEST(RmDirRecursively) { - string const testDir1 = base::JoinFoldersToPath(GetPlatform().WritableDir(), "test_dir1"); + string const testDir1 = base::JoinPath(GetPlatform().WritableDir(), "test_dir1"); TEST_EQUAL(Platform::MkDir(testDir1), Platform::ERR_OK, ()); SCOPE_GUARD(removeTestDir1, bind(&Platform::RmDir, testDir1)); - string const testDir2 = base::JoinFoldersToPath(testDir1, "test_dir2"); + string const testDir2 = base::JoinPath(testDir1, "test_dir2"); TEST_EQUAL(Platform::MkDir(testDir2), Platform::ERR_OK, ()); SCOPE_GUARD(removeTestDir2, bind(&Platform::RmDir, testDir2)); - string const filePath = base::JoinFoldersToPath(testDir2, "test_file"); + string const filePath = base::JoinPath(testDir2, "test_file"); { FileWriter testFile(filePath); testFile.Write("HOHOHO", 6); diff --git a/platform/platform_tests_support/scoped_dir.cpp b/platform/platform_tests_support/scoped_dir.cpp index 4f23ff312e..67ef05e1a6 100644 --- a/platform/platform_tests_support/scoped_dir.cpp +++ b/platform/platform_tests_support/scoped_dir.cpp @@ -13,9 +13,9 @@ namespace platform namespace tests_support { ScopedDir::ScopedDir(string const & relativePath) - : m_fullPath(base::JoinFoldersToPath(GetPlatform().WritableDir(), relativePath)), - m_relativePath(relativePath), - m_reset(false) + : m_fullPath(base::JoinPath(GetPlatform().WritableDir(), relativePath)) + , m_relativePath(relativePath) + , m_reset(false) { Platform::EError ret = Platform::MkDir(GetFullPath()); switch (ret) @@ -34,7 +34,7 @@ ScopedDir::ScopedDir(string const & relativePath) } ScopedDir::ScopedDir(ScopedDir const & parent, string const & name) - : ScopedDir(base::JoinFoldersToPath(parent.GetRelativePath(), name)) + : ScopedDir(base::JoinPath(parent.GetRelativePath(), name)) { } diff --git a/platform/platform_tests_support/scoped_file.cpp b/platform/platform_tests_support/scoped_file.cpp index 25ccf5be3c..f7fc36d75e 100644 --- a/platform/platform_tests_support/scoped_file.cpp +++ b/platform/platform_tests_support/scoped_file.cpp @@ -40,7 +40,7 @@ ScopedFile::ScopedFile(ScopedDir const & dir, CountryFile const & countryFile, } ScopedFile::ScopedFile(string const & relativePath, string const & contents, Mode mode) - : m_fullPath(base::JoinFoldersToPath(GetPlatform().WritableDir(), relativePath)) + : m_fullPath(base::JoinPath(GetPlatform().WritableDir(), relativePath)) { if (mode == Mode::DoNotCreate) return; |