Fixed svace.(FILE_SYSTEM_REALPATH)
[platform/core/dotnet/launcher.git] / NativeLauncher / util / path_manager.cc
index 8644bf0..5df09ba 100644 (file)
@@ -25,7 +25,6 @@
 #include "log.h"
 
 static const char* __TIZEN_API_PATH_KEY = "db/dotnet/tizen_api_path";
-static const char* PLATFORM_TPA_CACHE = "/usr/share/dotnet.tizen/lib/platform_tpa_cache";
 
 #define __XSTR(x) #x
 #define __STR(x) __XSTR(x)
@@ -43,10 +42,16 @@ typedef struct DllPath {
 
 static DllPath* __dllPath = nullptr;
 static std::string __tpa;
+bool initializedPathManager = false;
 
 // on success, return 0. otherwise return -1.
 int initializePathManager(const std::string& runtimeDir, const std::string& tizenFXDir, const std::string& extraDir)
 {
+       if (initializedPathManager) {
+               _INFO("Path manager already initialized");
+               return 0;
+       }
+
        __dllPath = new DllPath();
        if (!__dllPath) {
                _ERR("fail to allocate memory for dll path structure\n");
@@ -66,6 +71,7 @@ int initializePathManager(const std::string& runtimeDir, const std::string& tize
                if (tmp) {
                        __dllPath->tizenfx_dir = std::string(tmp);
                        _DBG("Device API Directory is set by vconf : %s", tmp);
+                       free(tmp);
                } else {
                        __dllPath->tizenfx_dir = absolutePath(__DEVICE_API_DIR);
                }
@@ -85,6 +91,7 @@ int initializePathManager(const std::string& runtimeDir, const std::string& tize
 
        _INFO("Path manager initialize success");
 
+       initializedPathManager = true;
        return 0;
 }
 
@@ -94,6 +101,8 @@ void finalizePathManager()
                delete __dllPath;
                __dllPath = NULL;
        }
+
+       initializedPathManager = false;
 }
 
 std::string getRuntimeDir()
@@ -121,7 +130,7 @@ static std::string getPlatformTPA()
        std::string platform_tpa;
 
        if (isFileExist(PLATFORM_TPA_CACHE)) {
-               _INFO("platform tpa cache found.\n");
+               _INFO("platform tpa cache found.");
                std::ifstream cacheFile;
                cacheFile.open(PLATFORM_TPA_CACHE);
                std::getline(cacheFile, platform_tpa);
@@ -137,6 +146,22 @@ static std::string getPlatformTPA()
        return platform_tpa;
 }
 
+static std::string getPluginTPA()
+{
+       std::string plugin_tpa;
+
+       char* plugin_tpa_list = pluginGetTPA();
+       if (plugin_tpa_list) {
+               _INFO("plugin TPA list found. use TPA list for plugin");
+               plugin_tpa = plugin_tpa_list;
+       } else if (!__dllPath->extra_dirs.empty()){
+               _INFO("plugin extra directory found. use plugin extra directroy for TPA");
+               assembliesInDirectory(__dllPath->extra_dirs, plugin_tpa);
+       }
+
+       return plugin_tpa;
+}
+
 std::string getTPA()
 {
        if (!__tpa.empty()) {
@@ -147,14 +172,6 @@ std::string getTPA()
                return std::string("");
        }
 
-       __tpa = getPlatformTPA();
-
-       char* pluginTPA = pluginGetTPA();
-       if (pluginTPA) {
-               _INFO("plugin tpa found.\n");
-               __tpa = __tpa + ":" + pluginTPA;
-       }
-
-       return __tpa;
+       return getPlatformTPA() + ":" + getPluginTPA();
 }