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 bool aotPluginInstalled = false;
34 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
36 // Can be multiple apps in one package
37 if (aotPluginInstalled) {
38 _INFO("AOT plugin already installed");
41 aotPluginInstalled = true;
44 if (!pkgmgr_installer_info_get_skip_optimization(&skipOpt)) {
46 _DBG("Skip dotnet AOT");
51 std::string metaValue = getMetadataValue(std::string(pkgId), AOT_METADATA_KEY);
52 if (metaValue.empty()) {
53 _ERR("Failed to get metadata from [%s]", pkgId);
57 if (metaValue == METADATA_VALUE) {
58 _DBG("Prefer dotnet application AOT set TRUE");
60 NICommonOption option = {std::string(), std::string(), std::string()};
61 if (initNICommon(&option) < 0) {
62 _ERR("Fail to initialize NI Common");
66 if (createNIUnderPkgRoot(pkgId, 0) != NI_ERROR_NONE) {
67 _ERR("Failed to get root path from [%s]", pkgId);
70 _INFO("Complete make application to native image");
73 std::string rootPath = getRootPath(std::string(pkgId));
74 if (rootPath.empty()) {
75 _ERR("Failed to get root path from [%s]", pkgId);
79 std::string binDir = concatPath(rootPath, "bin");
80 std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
81 if (bf::exists(tacDir)) {
84 if (pkgmgr_installer_info_get_target_uid(&g_uid) < 0) {
85 _ERR("Failed to get UID");
89 for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
90 std::string symPath = symlinkAssembly.path().string();
91 if (!isNativeImage(symPath)) {
92 std::string originPath = bf::read_symlink(symPath).string();
93 std::string originNIPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
94 if (!bf::exists(originNIPath)) {
95 if (createNIDllUnderPkgRoot(pkgId, originPath, 0) != NI_ERROR_NONE) {
96 _ERR("Failed to create NI file [%s]", originPath.c_str());
100 std::string setNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
101 if (!bf::exists(setNIPath)) {
102 bf::create_symlink(originNIPath, setNIPath);
103 _INFO("%s symbolic link file generated successfully.", setNIPath.c_str());
104 if (lchown(setNIPath.c_str(), g_uid, g_gid)) {
105 _ERR("Failed to change owner of: %s", setNIPath.c_str());
111 } catch (const bf::filesystem_error& error) {
112 _ERR("File system error while interating files: %s", error.what());
120 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
122 return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgId, appId, list);
125 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
130 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
132 return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
135 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
140 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)