Change the extension of a path or file
authorj-h.choi <j-h.choi@samsung.com>
Wed, 9 Jun 2021 01:24:38 +0000 (10:24 +0900)
committer조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Wed, 9 Jun 2021 05:15:25 +0000 (14:15 +0900)
Change-Id: I2b0f5d2c00d2f84b5e2af25102ba50d29b7bee74

NativeLauncher/inc/utils.h
NativeLauncher/tool/ni_common.cc
NativeLauncher/tool/tac_common.cc
NativeLauncher/util/utils.cc

index 505fba9..a6b1d2d 100644 (file)
@@ -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
index c2d9c54..8302c77 100644 (file)
@@ -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();
index 9335325..ca666f0 100644 (file)
@@ -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<std::string> depsJsonParser(const std::string& rootPath, const std::string& execName)
 {
        std::vector<std::string> 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)) {
index 00cb0c8..6611f6e 100644 (file)
@@ -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;