2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "ni_common.h"
25 #include <pkgmgr_installer_info.h>
30 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
32 typedef struct Metadata {
37 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
41 Metadata *mdInfo = NULL;
42 tag = g_list_first(list);
44 mdInfo = (Metadata*)tag->data;
45 if (strcmp(mdInfo->key, AOT_METADATA_KEY) == 0 && strcmp(mdInfo->value, METADATA_VALUE) == 0) {
46 _DBG("Prefer dotnet application AOT set TRUE");
49 tag = g_list_next(tag);
53 NiCommonOption option = {std::string(), std::string(), std::string()};
54 if (initNICommon(&option) < 0) {
55 _ERR("Fail to initialize NI Common");
59 if (createNiUnderPkgRoot(pkgId, 0) != NI_ERROR_NONE) {
60 _ERR("Failed to get root path from [%s]", pkgId);
63 _INFO("Complete make application to native image");
67 if (getRootPath(pkgId, pkgRoot) < 0) {
68 _ERR("Failed to get root path from [%s]", pkgId);
72 std::string binDir = concatPath(pkgRoot, "bin");
73 std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
74 if (bf::exists(tacDir)) {
76 if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
77 _ERR("Failed to get UID");
81 for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
82 std::string symPath = symlinkAssembly.path().string();
83 if (!isNativeImage(symPath)) {
84 std::string originPath = bf::read_symlink(symPath).string();
85 std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
86 if (!bf::exists(originNiPath)) {
87 if(createNiDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) {
88 _ERR("Failed to create NI file [%s]", originPath.c_str());
92 std::string setNiPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
93 if (!bf::exists(setNiPath)) {
94 bf::create_symlink(originNiPath, setNiPath);
95 _INFO("%s symbolic link file generated successfully.", setNiPath.c_str());
96 if (lchown(setNiPath.c_str(), uid, 0)) {
97 _ERR("Failed to change owner of: %s", setNiPath.c_str());
103 } catch (const bf::filesystem_error& error) {
104 _ERR("File system error while interating files: %s", error.what());
112 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
114 return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgId, appId, list);
117 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
122 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
124 return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
127 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
132 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)