Code cleanup (#251)
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / prefer_dotnet_aot_plugin.cc
index b337820..17a0718 100644 (file)
 #endif
 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
 
-typedef struct Metadata {
-       const char *key;
-       const char *value;
-} Metadata;
-
 bool aotPluginInstalled = false;
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
@@ -53,20 +48,15 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                }
        }
 
-       GList *tag = NULL;
-       bool mdValue = false;
-       Metadata *mdInfo = NULL;
-       tag = g_list_first(list);
-       while (tag) {
-               mdInfo = (Metadata*)tag->data;
-               if (strcmp(mdInfo->key, AOT_METADATA_KEY) == 0 && strcmp(mdInfo->value, METADATA_VALUE) == 0) {
-                       _DBG("Prefer dotnet application AOT set TRUE");
-                       mdValue = true;
-               }
-               tag = g_list_next(tag);
+       std::string metaValue = getMetadataValue(std::string(pkgId), AOT_METADATA_KEY);
+       if (metaValue.empty()) {
+               _ERR("Failed to get metadata from [%s]", pkgId);
+               return 0;
        }
 
-       if (mdValue) {
+       if (metaValue == METADATA_VALUE) {
+               _DBG("Prefer dotnet application AOT set TRUE");
+
                NICommonOption option = {std::string(), std::string(), std::string()};
                if (initNICommon(&option) < 0) {
                        _ERR("Fail to initialize NI Common");
@@ -80,20 +70,20 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                        _INFO("Complete make application to native image");
                }
 
-               std::string pkgRoot;
-               if (getRootPath(pkgId, pkgRoot) < 0) {
+               std::string rootPath = getRootPath(std::string(pkgId));
+               if (rootPath.empty()) {
                        _ERR("Failed to get root path from [%s]", pkgId);
-                       return 0;
+                       return -1;
                }
 
-               std::string binDir = concatPath(pkgRoot, "bin");
+               std::string binDir = concatPath(rootPath, "bin");
                std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
                if (bf::exists(tacDir)) {
                        uid_t g_uid = 0;
                        gid_t g_gid = 0;
                        if (pkgmgr_installer_info_get_target_uid(&g_uid) < 0) {
                                _ERR("Failed to get UID");
-                               return 0;
+                               return -1;
                        }
                        try {
                                for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
@@ -102,7 +92,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                                                std::string originPath = bf::read_symlink(symPath).string();
                                                std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
                                                if (!bf::exists(originNIPath)) {
-                                                       if(createNIDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) {
+                                                       if (createNIDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) {
                                                                _ERR("Failed to create NI file [%s]", originPath.c_str());
                                                                return -1;
                                                        }