Revert PR #509, #510 (#513)
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / prefer_dotnet_aot_plugin.cc
index 17a0718..91928a7 100644 (file)
@@ -20,7 +20,8 @@
 
 #include <cstring>
 #include <vector>
-#include <sstream>
+
+#include <vconf.h>
 #include <glib.h>
 #include <pkgmgr_installer_info.h>
 
@@ -30,6 +31,7 @@
 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
 
 bool aotPluginInstalled = false;
+bool aotPluginFinished = false;
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
 {
@@ -51,68 +53,29 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
        std::string metaValue = getMetadataValue(std::string(pkgId), AOT_METADATA_KEY);
        if (metaValue.empty()) {
                _ERR("Failed to get metadata from [%s]", pkgId);
-               return 0;
+               return -1;
        }
 
-       if (metaValue == METADATA_VALUE) {
+       if (metaValue == METADATA_VALUE_TRUE) {
                _DBG("Prefer dotnet application AOT set TRUE");
 
-               NICommonOption option = {std::string(), std::string(), std::string()};
-               if (initNICommon(&option) < 0) {
+               if (initNICommon() != NI_ERROR_NONE) {
                        _ERR("Fail to initialize NI Common");
                        return -1;
                }
 
-               if (createNIUnderPkgRoot(pkgId, 0) != NI_ERROR_NONE) {
-                       _ERR("Failed to get root path from [%s]", pkgId);
+               NIOption* opt = getNIOption();
+               if (opt == nullptr) {
+                       _ERR("Fail to create option structure.");
                        return -1;
-               } else {
-                       _INFO("Complete make application to native image");
                }
 
-               std::string rootPath = getRootPath(std::string(pkgId));
-               if (rootPath.empty()) {
-                       _ERR("Failed to get root path from [%s]", pkgId);
+               if (createNIUnderPkgRoot(pkgId, opt) != NI_ERROR_NONE) {
+                       _ERR("Failed to generate application to native image [%s]", pkgId);
                        return -1;
                }
 
-               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 -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(), 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;
-                       }
-               }
+               _INFO("Complete make application to native image");
        }
        return 0;
 }
@@ -134,10 +97,26 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *app
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
 {
+       // Can be multiple apps in one package
+       if (aotPluginFinished) {
+               _INFO("AOT plugin already finished(CLEAN)");
+               return 0;
+       }
+       aotPluginFinished = true;
+
+       finalizeNICommon();
        return 0;
 }
 
 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)
 {
+       // Can be multiple apps in one package
+       if (aotPluginFinished) {
+               _INFO("AOT plugin already finished(UNDO)");
+               return 0;
+       }
+       aotPluginFinished = true;
+
+       finalizeNICommon();
        return 0;
 }