Fixed Svace issue
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / prefer_dotnet_aot_plugin.cc
index 470468e..161d8d6 100644 (file)
@@ -36,6 +36,14 @@ typedef struct Metadata {
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
 {
+       int skipOpt = false;
+       if (!pkgmgr_installer_info_get_skip_optimization(&skipOpt)) {
+               if (skipOpt) {
+                       _DBG("Skip dotnet AOT");
+                       return 0;
+               }
+       }
+
        GList *tag = NULL;
        bool mdValue = false;
        Metadata *mdInfo = NULL;
@@ -56,7 +64,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                        return -1;
                }
 
-               if (createNiUnderPkgRoot(pkgId, false) != NI_ERROR_NONE) {
+               if (createNiUnderPkgRoot(pkgId, 0) != NI_ERROR_NONE) {
                        _ERR("Failed to get root path from [%s]", pkgId);
                        return -1;
                } else {
@@ -72,32 +80,38 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                std::string binDir = concatPath(pkgRoot, "bin");
                std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
                if (bf::exists(tacDir)) {
-                       uid_t uid = 0;
-                       if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
+                       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;
                        }
-                       for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
-                               std::string symPath = symlinkAssembly.path().string();
-                               if (!isNativeImage(symPath)) {
-                                       std::string originPath = bf::read_symlink(symPath).string();
-                                       std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
-                                       if (!bf::exists(originNiPath)) {
-                                               if(createNiDll(originPath, false) != NI_ERROR_NONE) {
-                                                       _ERR("Failed to create NI file [%s]", originPath.c_str());
-                                                       return -1;
+                       try {
+                               for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+                                       std::string symPath = symlinkAssembly.path().string();
+                                       if (!isNativeImage(symPath)) {
+                                               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) {
+                                                               _ERR("Failed to create NI file [%s]", originPath.c_str());
+                                                               return -1;
+                                                       }
                                                }
-                                       }
-                                       std::string setNiPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
-                                       if (!bf::exists(setNiPath)) {
-                                               bf::create_symlink(originNiPath, setNiPath);
-                                               _INFO("%s symbolic link file generated successfully.", setNiPath.c_str());
-                                               if (lchown(setNiPath.c_str(), uid, 0)) {
-                                                       _ERR("Failed to change owner of: %s", setNiPath.c_str());
-                                                       return -1;
+                                               std::string setNiPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
+                                               if (!bf::exists(setNiPath)) {
+                                                       bf::create_symlink(originNiPath, setNiPath);
+                                                       _INFO("%s symbolic link file generated successfully.", setNiPath.c_str());
+                                                       if (lchown(setNiPath.c_str(), g_uid, g_gid)) {
+                                                               _ERR("Failed to change owner of: %s", setNiPath.c_str());
+                                                               return -1;
+                                                       }
                                                }
                                        }
                                }
+                       } catch (const bf::filesystem_error& error) {
+                               _ERR("File system error while interating files: %s", error.what());
+                               return -1;
                        }
                }
        }