2 * Copyright (c) 2019 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.
19 #include "db_manager.h"
20 #include "tac_common.h"
27 #include <boost/filesystem.hpp>
29 #include <json/json.h>
30 #include <pkgmgr-info.h>
35 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
38 #define __STR(x) __XSTR(x)
39 static const char* __DOTNET_DIR = __STR(DOTNET_DIR);
43 std::vector<std::string> nugetPackagesAssembliesSha;
44 std::vector<std::string> tacDB;
45 std::vector<std::string> createDirectories;
46 std::vector<std::string> createLibraries;
47 std::vector<std::string> updateTac;
48 std::string status = "";
49 static sqlite3 *tac_db = NULL;
50 static sqlite3 *tlc_db = NULL;
51 bool tacPluginInstalled = false;
52 bool tacPluginFinished = false;
54 static void createSHA256Info(std::string sha256Info, std::string nugetPackage)
56 std::ofstream ofs(sha256Info, std::ios::app);
57 int assembly_count = 0;
58 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
59 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
60 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
61 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
62 std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
63 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
64 ofs << assembly << ":" << sha << std::endl;
68 ofs << assembly_count << std::endl;
72 static bool compareSHA256Info(std::string sha256Info, std::string nugetPackage)
74 int compare_count = 0;
75 int assembly_count = 0;
76 std::string sha256_count = "0";
77 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
78 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
79 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
80 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
81 std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
82 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
84 std::ifstream ifs(sha256Info);
87 while (getline(ifs, get_str)) {
88 if (!strcmp(get_str.c_str(), (assembly + ":" + sha).c_str())) {
91 sha256_count = get_str;
97 if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
98 !strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
99 _INFO("Same nuget : %s", nugetPackage.c_str());
105 static bool copyAssemblyCreateSymlink(std::string binPath, std::string tacDir, std::string nugetPackage, bool isCreateTacDir)
107 std::string tac_version_dir = concatPath(__DOTNET_DIR, nugetPackage);
108 bool nuget_restoration = false;
109 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
110 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
111 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
112 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
113 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
114 if (exist(concatPath(binPath, assembly))) {
115 if (isCreateTacDir) {
116 if (!copyFile(concatPath(binPath, assembly), concatPath(tac_version_dir, assembly))) {
117 _ERR("Failed to copy of %s", assembly.c_str());
118 nuget_restoration = true;
122 bf::create_symlink(concatPath(tac_version_dir, assembly), concatPath(tacDir, assembly));
124 if (!removeFile(concatPath(binPath, assembly))) {
125 _ERR("Failed to remove of %s", assembly.c_str());
126 nuget_restoration = true;
133 if (nuget_restoration) {
134 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
135 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
136 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
137 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
138 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
139 copyFile(concatPath(tac_version_dir, assembly), concatPath(binPath, assembly));
140 removeFile(concatPath(tacDir, assembly));
145 return nuget_restoration;
148 static void copyLibraryCreateSymlink(const char* pkgId, std::vector<std::string> LibrariesInfo, std::string tlcDir)
150 if (LibrariesInfo.empty()) {
151 _INFO("Not exist data for TLC in %s", pkgId);
155 for (auto& librarySha : LibrariesInfo) {
156 std::string library = librarySha.substr(0, librarySha.find(':'));
157 std::string filename = library.substr(library.rfind('/') + 1);
158 std::string fileSha = filename + ".." + librarySha.substr(librarySha.find(':') + 1);
159 bool fileCopied = false;
160 if (!exist(concatPath(tlcDir, fileSha))) {
161 if (!copyFile(library, concatPath(tlcDir, fileSha))) {
162 _ERR("Failed to copy of %s", filename.c_str());
166 createLibraries.push_back(concatPath(tlcDir, fileSha));
168 if (!removeFile(library)) {
169 _ERR("Failed to remove of %s", library.c_str());
171 removeFile(concatPath(tlcDir, fileSha));
175 bf::create_symlink(concatPath(tlcDir, fileSha), library);
177 char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
178 if (!insertDB(tlc_db, sql)) {
179 _ERR("Sqlite insert error");
181 copyFile(concatPath(tlcDir, fileSha), library);
183 removeFile(concatPath(tlcDir, fileSha));
191 static void checkDepsJson(std::string rootPath, std::string binPath, std::string execName)
193 for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
194 std::string nuget_package = npAssembly.substr(0, npAssembly.rfind(':'));
195 std::string assembly_name = npAssembly.substr(npAssembly.rfind(':') + 1);
196 tacDB.push_back(nuget_package);
197 std::string buffer = SHA256(concatPath(binPath, assembly_name));
198 nugetPackagesAssembliesSha.push_back(nuget_package + ":" + assembly_name + ":" + buffer);
199 _INFO("Assembly : [%s] / SHA256 : [%s]", assembly_name.c_str(), buffer.c_str());
201 std::sort(tacDB.begin(), tacDB.end());
202 tacDB.erase(unique(tacDB.begin(), tacDB.end()), tacDB.end());
205 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
207 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_INSTALL =====]");
208 _INFO("PackageID : %s", pkgId);
210 // Can be multiple apps in one package
211 if (tacPluginInstalled) {
212 _INFO("TAC plugin already installed");
215 tacPluginInstalled = true;
217 std::string appType = getAppType(std::string(pkgId));
218 if (strstr(appType.c_str(), "dotnet") == NULL) {
219 _ERR("App type is not dotnet");
222 std::string execName = getExecName(std::string(pkgId));
223 std::string rootPath = getRootPath(std::string(pkgId));
224 if (execName.empty() || rootPath.empty()) {
227 std::string binPath = concatPath(rootPath, "bin");
228 std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
229 if (metaValue.empty()) {
232 if (metaValue == METADATA_VALUE) {
233 checkDepsJson(rootPath, binPath, execName);
238 _INFO("Not exist data for TAC in %s", pkgId);
242 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
244 _ERR("Sqlite create error. So restore the database.");
245 if (tac_restoreDB() != TAC_ERROR_NONE) {
246 _ERR("Sqlite create error");
249 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
251 _ERR("Sqlite create error");
255 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
257 std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
258 if (!createDir(tac_dir)) {
259 _ERR("Cannot create directory: %s", tac_dir.c_str());
262 copySmackAndOwnership(binPath.c_str(), tac_dir.c_str());
264 for (auto& np : tacDB) {
265 std::string tac_name = np.substr(0, np.find('/'));
266 std::string tac_version = np.substr(np.rfind('/') + 1);
267 _INFO("TAC name : %s", tac_name.c_str());
268 _INFO("TAC version : %s", tac_version.c_str());
270 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
271 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
272 if (!exist(tac_version_dir)) {
273 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
274 if (!createDir(tac_version_dir)) {
275 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
279 createDirectories.push_back(tac_version_dir);
280 if (!bf::is_symlink(sha256_info)) {
281 createSHA256Info(sha256_info, np);
283 _ERR("Failed to create sha256_info. Symbolic link is detected");
288 if (!exist(sha256_info)) {
293 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, true)) {
294 _ERR("Failed to create symlink");
299 char *sql = sqlite3_mprintf(
300 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
301 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
302 if (!insertDB(tac_db, sql)) {
303 _ERR("Sqlite insert error");
310 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
311 if (!bf::is_symlink(sha256_info)) {
312 if (compareSHA256Info(sha256_info, np)) {
313 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, false)) {
314 _ERR("Failed to create symlink");
319 char *sql = sqlite3_mprintf(
320 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
321 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
322 if (!insertDB(tac_db, sql)) {
323 _ERR("Sqlite insert error");
330 _INFO("Different nuget : %s", np.c_str());
334 _ERR("Failed to create sha256_info. Symbolic link is detected");
342 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
343 if (!createDir(tlcDir)) {
344 _ERR("Cannot create directory: %s", tlcDir.c_str());
348 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
350 _ERR("Sqlite create error. So restore the database.");
351 if (tlc_restoreDB() != TAC_ERROR_NONE) {
352 _ERR("Sqlite create error");
355 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
357 _ERR("Sqlite create error");
361 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
363 copyLibraryCreateSymlink(pkgId, getLibrariesInfo(rootPath), tlcDir);
368 static int sqliteCb(void *count, int argc, char **argv, char **colName)
370 int *c = (int*)count;
375 static void tac_updateDB(sqlite3 *sqlite)
377 for (auto& unp : updateTac) {
379 char *sql = sqlite3_mprintf("SELECT COUNT(NUGET) FROM TAC WHERE NUGET = %Q;", unp.c_str());
380 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
381 if (ret != SQLITE_OK) {
382 _ERR("Sqlite select error");
387 std::string tac_version_dir_prev = concatPath(__DOTNET_DIR, unp);
388 std::string tac_version_dir_backup = tac_version_dir_prev + ".bck";
389 if (!copyDir(tac_version_dir_prev, tac_version_dir_backup)) {
390 _ERR("Failed to copy of %s to %s", tac_version_dir_prev.c_str(), tac_version_dir_backup.c_str());
394 if (!removeAll(tac_version_dir_prev)) {
395 _ERR("Failed to remove of %s", tac_version_dir_prev.c_str());
404 static void tlc_updateDB(sqlite3 *sqlite, std::vector<std::string> updateTlc, std::string tlcDir)
406 for (auto& ulp : updateTlc) {
408 char *sql = sqlite3_mprintf("SELECT COUNT(LIBRARY) FROM TLC WHERE LIBRARY = %Q;", ulp.c_str());
409 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
410 if (ret != SQLITE_OK) {
411 _ERR("Sqlite select error");
416 std::string library_prev = concatPath(tlcDir, ulp);
417 std::string library_backup = library_prev + ".bck";
418 if (!copyFile(library_prev, library_backup)) {
419 _ERR("Failed to copy of %s", library_prev.c_str());
423 if (!removeFile(library_prev)) {
424 _ERR("Failed to remove of %s", library_prev.c_str());
433 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
435 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
436 _INFO("PackageID : %s", pkgId);
438 // Can be multiple apps in one package
439 if (tacPluginInstalled) {
440 _INFO("TAC plugin already upgraded");
443 tacPluginInstalled = true;
445 std::string appType = getAppType(std::string(pkgId));
446 if (strstr(appType.c_str(), "dotnet") == NULL) {
447 _ERR("App type is not dotnet");
450 std::string execName = getExecName(std::string(pkgId));
451 std::string rootPath = getRootPath(std::string(pkgId));
452 if (execName.empty() || rootPath.empty()) {
455 std::string binPath = concatPath(rootPath, "bin");
457 if (!strcmp("removed", status.c_str())) {
458 _INFO("Skipped to parse of deps.json");
460 std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
461 if (metaValue.empty()) {
464 if (metaValue == METADATA_VALUE) {
465 checkDepsJson(rootPath, binPath, execName);
470 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
472 _ERR("Sqlite create error. So restore the database.");
473 if (tac_restoreDB() != TAC_ERROR_NONE) {
474 _ERR("Sqlite create error");
477 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
479 _ERR("Sqlite create error");
483 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
485 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
486 updateTac = selectDB(tac_db, sql);
489 bool skipTLC = false;
491 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
492 if (!deleteDB(tac_db, sql)) {
493 _ERR("Sqlite delete error");
499 tac_updateDB(tac_db);
502 _INFO("Not exist data for TAC in %s", pkgId);
504 std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
505 if (!createDir(tac_dir)) {
506 _ERR("Cannot create directory: %s", tac_dir.c_str());
509 copySmackAndOwnership(binPath.c_str(), tac_dir.c_str());
511 for (auto& np : tacDB) {
512 std::string tac_name = np.substr(0, np.find('/'));
513 std::string tac_version = np.substr(np.rfind('/') + 1);
514 _INFO("TAC name : %s", tac_name.c_str());
515 _INFO("TAC version : %s", tac_version.c_str());
517 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
518 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
519 if (!exist(tac_version_dir)) {
520 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
521 if (!createDir(tac_version_dir)) {
522 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
526 createDirectories.push_back(tac_version_dir);
527 if (!bf::is_symlink(sha256_info)) {
528 createSHA256Info(sha256_info, np);
530 _ERR("Failed to create sha256_info. Symbolic link is detected");
535 if (!exist(sha256_info)) {
540 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, true)) {
541 _ERR("Failed to create symlink");
547 sql = sqlite3_mprintf(
548 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
549 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
550 if (ret != SQLITE_OK) {
551 _ERR("Sqlite select error");
558 sql = sqlite3_mprintf(
559 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
560 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
561 if (!updateDB(tac_db, sql)) {
562 _ERR("Sqlite update error");
568 } else if (count == 0) {
569 sql = sqlite3_mprintf(
570 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
571 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
572 if (!insertDB(tac_db, sql)) {
573 _ERR("Sqlite insert error");
581 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
582 if (!bf::is_symlink(sha256_info)) {
583 if (compareSHA256Info(sha256_info, np)) {
584 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, false)) {
585 _ERR("Failed to create symlink");
591 char *sql = sqlite3_mprintf(
592 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
593 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
594 if (ret != SQLITE_OK) {
595 _ERR("Sqlite select error");
602 sql = sqlite3_mprintf(
603 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
604 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
605 if (!updateDB(tac_db, sql)) {
606 _ERR("Sqlite update error");
612 } else if (count == 0) {
613 sql = sqlite3_mprintf(
614 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
615 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
616 if (!insertDB(tac_db, sql)) {
617 _ERR("Sqlite insert error");
625 _INFO("Different nuget : %s", np.c_str());
629 _ERR("Failed to create sha256_info. Symbolic link is detected");
635 for (auto& unp : updateTac) {
636 bool isExits = false;
637 for (auto& np : tacDB) {
638 if (!strcmp(unp.c_str(), np.c_str())) {
644 char *sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q AND NUGET = %Q;", pkgId, unp.c_str());
645 if (!deleteDB(tac_db, sql)) {
646 _ERR("Sqlite delete error");
654 tac_updateDB(tac_db);
658 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
659 if (!createDir(tlcDir)) {
660 _ERR("Cannot create directory: %s", tlcDir.c_str());
664 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
666 _ERR("Sqlite create error. So restore the database.");
667 if (tlc_restoreDB() != TAC_ERROR_NONE) {
668 _ERR("Sqlite create error");
671 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
673 _ERR("Sqlite create error");
677 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
679 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
680 std::vector<std::string> updateTlc = selectDB(tlc_db, sql);
683 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
684 if (!deleteDB(tlc_db, sql)) {
685 _ERR("Sqlite delete error");
691 std::vector<std::string> librariesInfo;
693 librariesInfo = getLibrariesInfo(rootPath);
696 copyLibraryCreateSymlink(pkgId, librariesInfo, tlcDir);
698 tlc_updateDB(tlc_db, updateTlc, tlcDir);
703 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
705 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNINSTALL =====]");
706 _INFO("PackageID : %s", pkgId);
708 // Can be multiple apps in one package
709 if (tacPluginInstalled) {
710 _INFO("TAC plugin already uninstalled");
713 tacPluginInstalled = true;
715 status = "uninstall";
716 tac_db = openDB(TAC_APP_LIST_DB);
718 _ERR("Sqlite open error. So restore the database.");
719 if (tac_restoreDB() != TAC_ERROR_NONE) {
720 _ERR("Sqlite open error");
723 tac_db = openDB(TAC_APP_LIST_DB);
725 _ERR("Sqlite open error");
729 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
731 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
732 updateTac = selectDB(tac_db, sql);
735 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
737 if (!deleteDB(tac_db, sql)) {
738 _ERR("Sqlite delete error");
745 tac_updateDB(tac_db);
748 tlc_db = openDB(TLC_APP_LIST_DB);
750 _ERR("Sqlite open error. So restore the database.");
751 if (tlc_restoreDB() != TAC_ERROR_NONE) {
752 _ERR("Sqlite open error");
755 tlc_db = openDB(TLC_APP_LIST_DB);
757 _ERR("Sqlite open error");
761 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
763 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
764 std::vector<std::string> updateTlc = selectDB(tlc_db, sql);
767 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
768 if (!deleteDB(tlc_db, sql)) {
769 _ERR("Sqlite delete error");
775 tlc_updateDB(tlc_db, updateTlc, concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR));
780 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
782 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_REMOVED =====]");
783 _INFO("PackageID : %s", pkgId);
787 return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
790 void undoStep(std::string tac)
792 std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
794 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
795 std::string bck_path = bck.path().string();
796 if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
797 if (!moveFile(bck_path, bck_path.substr(0, bck_path.rfind(".bck")))) {
798 _ERR("Failed to move %s", bck_path.c_str());
803 } catch (const bf::filesystem_error& error) {
804 _ERR("Failed to recursive directory: %s", error.what());
809 auto convert = [](const std::string& path, const std::string& filename) {
810 if (filename.rfind(".bck") != std::string::npos) {
811 if (!moveFile(path, replaceAll(path, ".bck", ""))) {
812 _ERR("Failed to move %s", path.c_str());
817 scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
822 for (auto& cd : createDirectories) {
823 if (!removeAll(cd)) {
824 _ERR("Failed to remove of %s", cd.c_str());
828 for (auto& cl : createLibraries) {
829 if (!removeFile(cl)) {
830 _ERR("Failed to remove of %s", cl.c_str());
835 void unInstall_Undo()
837 for (auto& unp : updateTac) {
845 if (!tacDB.empty()) {
846 for (auto& np : tacDB) {
853 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)
855 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNDO =====]");
856 _INFO("PackageID : %s", pkgId);
858 // Can be multiple apps in one package
859 if (tacPluginFinished) {
860 _INFO("TAC plugin already finished(UNDO)");
863 tacPluginFinished = true;
865 if (!strcmp("install", status.c_str())) {
867 } else if (!strcmp("update", status.c_str())) {
869 } else if (!strcmp("uninstall", status.c_str())) {
871 } else if (!strcmp("restore", status.c_str())) {
888 void cleanStep(std::string tac)
890 std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
892 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
893 std::string bck_path = bck.path().string();
894 if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
895 if (!removeAll(bck_path)) {
896 _ERR("Failed to remove of %s", bck_path.c_str());
902 bool isExist = false;
903 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
904 std::string bck_path = bck.path().string();
905 if (exist(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
911 if (!removeAll(current_tac)) {
912 _ERR("Failed to remove of %s", current_tac.c_str());
915 } catch (const bf::filesystem_error& error) {
916 _ERR("Failed to recursive directory: %s", error.what());
921 auto convert = [](const std::string& path, const std::string& filename) {
922 if (filename.rfind(".bck") != std::string::npos) {
923 if (!removeFile(path)) {
924 _ERR("Failed to remove of %s", path.c_str());
929 scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
937 void unInstall_Clean()
939 for (auto& unp : updateTac) {
946 if (!tacDB.empty()) {
947 for (auto& np : tacDB) {
954 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
956 if (!strcmp("restore", status.c_str())) {
957 disableTACPackage(pkgId);
959 std::string rootPath = getRootPath(std::string(pkgId));
960 if (!rootPath.empty()) {
961 std::string binPath = concatPath(rootPath, "bin");
962 removeAll(concatPath(binPath, TAC_SYMLINK_SUB_DIR));
965 std::string runtimesDir = concatPath(rootPath, "bin/runtimes");
966 if (exist(runtimesDir)) {
968 sprintf(buffer, "(tizen|linux|unix|base|any)(.\\d.\\d.\\d)?(-%s)?", ARCHITECTURE_IDENTIFIER);
969 std::regex pattern(buffer);
972 for (auto& path : bf::recursive_directory_iterator(runtimesDir)) {
973 std::string symPath = path.path().string();
974 if (isDirectory(symPath) || !bf::is_symlink(symPath))
976 std::string targetDir = symPath.substr(symPath.rfind("/runtimes/") + 10);
977 if (!std::regex_match(targetDir.substr(0, targetDir.find('/')), pattern))
979 if (symPath.rfind(".so") == std::string::npos)
981 copyFile(bf::read_symlink(symPath).string(), symPath);
983 } catch (const bf::filesystem_error& error) {
984 _ERR("Failed to recursive directory: %s", error.what());
988 return PKGMGR_MDPARSER_PLUGIN_UNDO(pkgId, appId, list);
991 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_CLEAN =====]");
992 _INFO("PackageID : %s", pkgId);
994 // Can be multiple apps in one package
995 if (tacPluginFinished) {
996 _INFO("TAC plugin already finished(CLEAN)");
999 tacPluginFinished = true;
1001 if (!strcmp("install", status.c_str())) {
1003 } else if (!strcmp("update", status.c_str())) {
1005 } else if (!strcmp("uninstall", status.c_str())) {