From 9e7498640854cf8f9b30219179b1ccb589f94095 Mon Sep 17 00:00:00 2001 From: "j-h.choi" Date: Wed, 9 Jun 2021 10:24:38 +0900 Subject: [PATCH 1/1] Change the extension of a path or file Change-Id: I2b0f5d2c00d2f84b5e2af25102ba50d29b7bee74 --- NativeLauncher/inc/utils.h | 9 +++++++++ NativeLauncher/tool/ni_common.cc | 4 ++-- NativeLauncher/tool/tac_common.cc | 6 +++--- NativeLauncher/util/utils.cc | 5 +++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h index 505fba9..a6b1d2d 100644 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -101,6 +101,15 @@ std::string getAppType(const std::string& pkgId); std::string getMetadataValue(const std::string& pkgId, const std::string& key); /** + * @brief change the extension of a path or file + * @param[in] source path or file + * @param[in] from extension + * @param[in] to extension + * @return std::string path or file with changed extension + */ +std::string changeExtension(const std::string& path, const std::string& from, const std::string& to); + +/** * @brief check the package is 'readonly' or not * @param[in] package id * @return bool package readonly value diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index c2d9c54..8302c77 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -613,14 +613,14 @@ ni_error_e createNIUnderDirs(const std::string& rootPaths, DWORD flags) } // if there is symlink and original file for native image, skip generation - std::string symNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll"; + std::string symNIPath = changeExtension(symPath, "dll", "ni.dll"); if (isFile(symNIPath)) { continue; } // if original native image not exist, generate native image std::string originPath = bf::read_symlink(symPath).string(); - std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; + std::string originNIPath = changeExtension(originPath, "dll", "ni.dll"); if (!isFile(originNIPath)) { if (!crossgen(originPath, path.c_str(), flags)) { waitInterval(); diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index 9335325..ca666f0 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -300,9 +300,9 @@ tac_error_e enableTACPackage(const std::string& pkgId) for (auto& originPath : enableNuget) { if (exist(originPath)) { std::string fileName = originPath.substr(originPath.rfind('/') + 1); - std::string NIFileName = fileName.substr(0, fileName.rfind(".dll")) + ".ni.dll"; + std::string NIFileName = changeExtension(fileName, "dll", "ni.dll"); if (exist(binNIDir)) { - std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll"; + std::string originNIPath = changeExtension(originPath, "dll", "ni.dll"); if (exist(originNIPath)) { bf::create_symlink(originNIPath, concatPath(tacDir, NIFileName)); fprintf(stdout, "%s symbolic link file generated successfully.\n", concatPath(tacDir, NIFileName).c_str()); @@ -341,7 +341,7 @@ tac_error_e enableTACPackage(const std::string& pkgId) std::vector depsJsonParser(const std::string& rootPath, const std::string& execName) { std::vector parserData; - std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json"; + std::string depsJsonName = changeExtension(execName, "dll", "deps.json"); std::string depsJsonPath = concatPath(rootPath, depsJsonName); try { if (exist(depsJsonPath)) { diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 00cb0c8..6611f6e 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -293,6 +293,11 @@ std::string replaceAll(const std::string& str, const std::string& pattern, const return result; } +std::string changeExtension(const std::string& path, const std::string& from, const std::string& to) +{ + return path.substr(0, path.rfind(from)) + to; +} + bool isFile(const std::string& path) { struct stat sb; -- 2.7.4