2 * Copyright (c) 2020 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.
26 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
28 typedef struct _xmlDoc xmlDoc;
29 typedef xmlDoc* xmlDocPtr;
31 bool pluginInstalled = false;
33 extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId)
35 // Can be multiple apps in one package
36 if (pluginInstalled) {
37 _INFO("Plugin already installed");
40 pluginInstalled = true;
42 std::string appType = getAppType(pkgId);
43 if (appType.empty()) {
44 _ERR("Failed to get app type from [%s]", pkgId);
48 if (appType.find("dotnet") == std::string::npos) {
52 std::string rootPath = getRootPath(pkgId);
53 if (rootPath.empty()) {
54 _ERR("Failed to get root path from [%s]", pkgId);
58 std::string runtimesDir = concatPath(rootPath, "bin/runtimes");
59 if (!exist(runtimesDir)) {
64 sprintf(buffer, "(tizen|linux|unix|base|any)(.\\d.\\d.\\d)?(-%s)?", ARCHITECTURE_IDENTIFIER);
65 std::regex pattern(buffer);
67 std::vector<std::string> unusedDir;
69 for (auto& path : bf::recursive_directory_iterator(runtimesDir)) {
70 std::string filepath = path.path().string();
71 std::string targetDir = filepath.substr(filepath.rfind("/runtimes/") + 10);
72 if (!std::regex_match(targetDir.substr(0, targetDir.find('/')), pattern)) {
73 if (isDirectory(filepath)) {
74 unusedDir.push_back(filepath);
78 } catch (const bf::filesystem_error& error) {
79 _ERR("Failed to recursive directory: %s", error.what());
82 for (auto& path : unusedDir) {
83 if (!removeAll(path)) {
84 _ERR("Failed to remove of %s", path.c_str());
91 extern "C" int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char* pkgId)
93 return PKGMGR_PARSER_PLUGIN_INSTALL(doc, pkgId);
95 extern "C" int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char* pkgId)
99 extern "C" int PKGMGR_PARSER_PLUGIN_REMOVED(xmlDocPtr doc, const char* pkgId)
103 extern "C" int PKGMGR_PARSER_PLUGIN_CLEAN(xmlDocPtr doc, const char* pkgId)
107 extern "C" int PKGMGR_PARSER_PLUGIN_UNDO(xmlDocPtr doc, const char* pkgId)
111 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *pkgId)
115 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *pkgId)
119 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *pkgId)
123 extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId)
127 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId)
131 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *pkgId)