* limitations under the License.
*/
-#include "common.h"
+#include "ni_common.h"
#include "log.h"
#include "utils.h"
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "NETCORE_INSTALLER_PLUGIN"
-
#include <cstring>
#include <vector>
#include <sstream>
#include <glib.h>
+#include <pkgmgr_installer_info.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
typedef struct Metadata {
- const char *key;
- const char *value;
+ const char *key;
+ const char *value;
} Metadata;
-const std::string VALUE_TRUE = "true";
-const std::string mdKey = "http://tizen.org/metadata/prefer_dotnet_aot";
-extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL (const char *pkgid, const char *appid, GList *list)
+extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
+{
+ 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);
+ }
+
+ if (mdValue) {
+ NiCommonOption option = {std::string(), std::string(), std::string()};
+ if (initNICommon(&option) < 0) {
+ _ERR("Fail to initialize NI Common");
+ return -1;
+ }
+
+ if (createNiUnderPkgRoot(pkgId, false) != NI_ERROR_NONE) {
+ _ERR("Failed to get root path from [%s]", pkgId);
+ return -1;
+ } else {
+ _INFO("Complete make application to native image");
+ }
+
+ std::string pkgRoot;
+ if (getRootPath(pkgId, pkgRoot) < 0) {
+ _ERR("Failed to get root path from [%s]", pkgId);
+ return 0;
+ }
+
+ 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) {
+ _ERR("Failed to get UID");
+ return 0;
+ }
+ 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(createNiDll(originPath, false) != 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;
+ }
+ }
+ }
+ }
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
{
+ return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgId, appId, list);
+}
- GList *tag = NULL;
- bool mdValue = false;
- Metadata *mdInfo = NULL;
- tag = g_list_first(list);
- while (tag) {
- mdInfo = (Metadata*)tag->data;
- if(mdInfo->key == mdKey && mdInfo->value == VALUE_TRUE) {
- _DBG("Prefer dotnet application AOT set TRUE");
- mdValue = true;
- }
- tag = g_list_next(tag);
- }
+extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
+{
+ return 0;
+}
- if (mdValue) {
- if (create_ni_under_pkg_root(pkgid) != 0)
- {
- _ERR("Failed to get root path from [%s]", pkgid);
- return -1;
- } else {
- _DBG("Complete make application to native image");
- }
- }
- return 0;
+extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
+{
+ return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
+}
+
+extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
+{
+ return 0;
}
-extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE (const char *pkgid, const char *appid, GList *list)
+extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)
{
- return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list);
+ return 0;
}