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));
123 copySmackAndOwnership(tacDir, concatPath(tacDir, assembly), true);
125 if (!removeFile(concatPath(binPath, assembly))) {
126 _ERR("Failed to remove of %s", assembly.c_str());
127 nuget_restoration = true;
134 if (nuget_restoration) {
135 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
136 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
137 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
138 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
139 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
140 copyFile(concatPath(tac_version_dir, assembly), concatPath(binPath, assembly));
141 copySmackAndOwnership(binPath, concatPath(binPath, assembly));
142 removeFile(concatPath(tacDir, assembly));
147 return nuget_restoration;
150 static void copyLibraryCreateSymlink(const char* pkgId, std::vector<std::string> LibrariesInfo, std::string tlcDir)
152 if (LibrariesInfo.empty()) {
153 _INFO("Not exist data for TLC in %s", pkgId);
157 for (auto& librarySha : LibrariesInfo) {
158 std::string library = librarySha.substr(0, librarySha.find(':'));
159 std::string filename = library.substr(library.rfind('/') + 1);
160 std::string fileSha = filename + ".." + librarySha.substr(librarySha.find(':') + 1);
161 bool fileCopied = false;
162 if (!exist(concatPath(tlcDir, fileSha))) {
163 if (!copyFile(library, concatPath(tlcDir, fileSha))) {
164 _ERR("Failed to copy of %s", filename.c_str());
168 createLibraries.push_back(concatPath(tlcDir, fileSha));
170 if (!removeFile(library)) {
171 _ERR("Failed to remove of %s", library.c_str());
173 removeFile(concatPath(tlcDir, fileSha));
177 bf::create_symlink(concatPath(tlcDir, fileSha), library);
178 copySmackAndOwnership(getBaseName(library), library, true);
180 char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
181 if (!insertDB(tlc_db, sql)) {
182 _ERR("Sqlite insert error");
184 copyFile(concatPath(tlcDir, fileSha), library);
185 copySmackAndOwnership(getBaseName(library), library);
187 removeFile(concatPath(tlcDir, fileSha));
195 static void checkDepsJson(std::string rootPath, std::string binPath, std::string execName)
197 for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
198 std::string nuget_package = npAssembly.substr(0, npAssembly.rfind(':'));
199 std::string assembly_name = npAssembly.substr(npAssembly.rfind(':') + 1);
200 tacDB.push_back(nuget_package);
201 std::string buffer = SHA256(concatPath(binPath, assembly_name));
202 nugetPackagesAssembliesSha.push_back(nuget_package + ":" + assembly_name + ":" + buffer);
203 _INFO("Assembly : [%s] / SHA256 : [%s]", assembly_name.c_str(), buffer.c_str());
205 std::sort(tacDB.begin(), tacDB.end());
206 tacDB.erase(unique(tacDB.begin(), tacDB.end()), tacDB.end());
209 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
211 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_INSTALL =====]");
212 _INFO("PackageID : %s", pkgId);
214 // Can be multiple apps in one package
215 if (tacPluginInstalled) {
216 _INFO("TAC plugin already installed");
219 tacPluginInstalled = true;
221 std::string appType = getAppType(std::string(pkgId));
222 if (strstr(appType.c_str(), "dotnet") == NULL) {
223 _ERR("App type is not dotnet");
226 std::string execName = getExecName(std::string(pkgId));
227 std::string rootPath = getRootPath(std::string(pkgId));
228 if (execName.empty() || rootPath.empty()) {
231 std::string binPath = concatPath(rootPath, "bin");
232 std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
233 if (metaValue.empty()) {
236 if (metaValue == METADATA_VALUE) {
237 checkDepsJson(rootPath, binPath, execName);
242 _INFO("Not exist data for TAC in %s", pkgId);
246 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
248 _ERR("Sqlite create error. So restore the database.");
249 if (tac_restoreDB() != TAC_ERROR_NONE) {
250 _ERR("Sqlite create error");
253 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
255 _ERR("Sqlite create error");
259 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
261 std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
262 if (!createDir(tac_dir)) {
263 _ERR("Cannot create directory: %s", tac_dir.c_str());
266 copySmackAndOwnership(binPath.c_str(), tac_dir.c_str());
268 for (auto& np : tacDB) {
269 std::string tac_name = np.substr(0, np.find('/'));
270 std::string tac_version = np.substr(np.rfind('/') + 1);
271 _INFO("TAC name : %s", tac_name.c_str());
272 _INFO("TAC version : %s", tac_version.c_str());
274 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
275 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
276 if (!exist(tac_version_dir)) {
277 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
278 if (!createDir(tac_version_dir)) {
279 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
283 createDirectories.push_back(tac_version_dir);
284 if (!bf::is_symlink(sha256_info)) {
285 createSHA256Info(sha256_info, np);
287 _ERR("Failed to create sha256_info. Symbolic link is detected");
292 if (!exist(sha256_info)) {
297 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, true)) {
298 _ERR("Failed to create symlink");
303 char *sql = sqlite3_mprintf(
304 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
305 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
306 if (!insertDB(tac_db, sql)) {
307 _ERR("Sqlite insert error");
314 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
315 if (!bf::is_symlink(sha256_info)) {
316 if (compareSHA256Info(sha256_info, np)) {
317 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, false)) {
318 _ERR("Failed to create symlink");
323 char *sql = sqlite3_mprintf(
324 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
325 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
326 if (!insertDB(tac_db, sql)) {
327 _ERR("Sqlite insert error");
334 _INFO("Different nuget : %s", np.c_str());
338 _ERR("Failed to create sha256_info. Symbolic link is detected");
346 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
347 if (!createDir(tlcDir)) {
348 _ERR("Cannot create directory: %s", tlcDir.c_str());
352 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
354 _ERR("Sqlite create error. So restore the database.");
355 if (tlc_restoreDB() != TAC_ERROR_NONE) {
356 _ERR("Sqlite create error");
359 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
361 _ERR("Sqlite create error");
365 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
367 copyLibraryCreateSymlink(pkgId, getLibrariesInfo(rootPath), tlcDir);
372 static int sqliteCb(void *count, int argc, char **argv, char **colName)
374 int *c = (int*)count;
379 static void tac_updateDB(sqlite3 *sqlite)
381 for (auto& unp : updateTac) {
383 char *sql = sqlite3_mprintf("SELECT COUNT(NUGET) FROM TAC WHERE NUGET = %Q;", unp.c_str());
384 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
385 if (ret != SQLITE_OK) {
386 _ERR("Sqlite select error");
391 std::string tac_version_dir_prev = concatPath(__DOTNET_DIR, unp);
392 std::string tac_version_dir_backup = tac_version_dir_prev + ".bck";
393 if (!copyDir(tac_version_dir_prev, tac_version_dir_backup)) {
394 _ERR("Failed to copy of %s to %s", tac_version_dir_prev.c_str(), tac_version_dir_backup.c_str());
398 if (!removeAll(tac_version_dir_prev)) {
399 _ERR("Failed to remove of %s", tac_version_dir_prev.c_str());
408 static void tlc_updateDB(sqlite3 *sqlite, std::vector<std::string> updateTlc, std::string tlcDir)
410 for (auto& ulp : updateTlc) {
412 char *sql = sqlite3_mprintf("SELECT COUNT(LIBRARY) FROM TLC WHERE LIBRARY = %Q;", ulp.c_str());
413 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
414 if (ret != SQLITE_OK) {
415 _ERR("Sqlite select error");
420 std::string library_prev = concatPath(tlcDir, ulp);
421 std::string library_backup = library_prev + ".bck";
422 if (!copyFile(library_prev, library_backup)) {
423 _ERR("Failed to copy of %s", library_prev.c_str());
427 if (!removeFile(library_prev)) {
428 _ERR("Failed to remove of %s", library_prev.c_str());
437 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
439 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
440 _INFO("PackageID : %s", pkgId);
442 // Can be multiple apps in one package
443 if (tacPluginInstalled) {
444 _INFO("TAC plugin already upgraded");
447 tacPluginInstalled = true;
449 std::string appType = getAppType(std::string(pkgId));
450 if (strstr(appType.c_str(), "dotnet") == NULL) {
451 _ERR("App type is not dotnet");
454 std::string execName = getExecName(std::string(pkgId));
455 std::string rootPath = getRootPath(std::string(pkgId));
456 if (execName.empty() || rootPath.empty()) {
459 std::string binPath = concatPath(rootPath, "bin");
461 if (!strcmp("removed", status.c_str())) {
462 _INFO("Skipped to parse of deps.json");
464 std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
465 if (metaValue.empty()) {
468 if (metaValue == METADATA_VALUE) {
469 checkDepsJson(rootPath, binPath, execName);
474 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
476 _ERR("Sqlite create error. So restore the database.");
477 if (tac_restoreDB() != TAC_ERROR_NONE) {
478 _ERR("Sqlite create error");
481 tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
483 _ERR("Sqlite create error");
487 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
489 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
490 updateTac = selectDB(tac_db, sql);
493 bool skipTLC = false;
495 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
496 if (!deleteDB(tac_db, sql)) {
497 _ERR("Sqlite delete error");
503 tac_updateDB(tac_db);
506 _INFO("Not exist data for TAC in %s", pkgId);
508 std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
509 if (!createDir(tac_dir)) {
510 _ERR("Cannot create directory: %s", tac_dir.c_str());
513 copySmackAndOwnership(binPath.c_str(), tac_dir.c_str());
515 for (auto& np : tacDB) {
516 std::string tac_name = np.substr(0, np.find('/'));
517 std::string tac_version = np.substr(np.rfind('/') + 1);
518 _INFO("TAC name : %s", tac_name.c_str());
519 _INFO("TAC version : %s", tac_version.c_str());
521 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
522 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
523 if (!exist(tac_version_dir)) {
524 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
525 if (!createDir(tac_version_dir)) {
526 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
530 createDirectories.push_back(tac_version_dir);
531 if (!bf::is_symlink(sha256_info)) {
532 createSHA256Info(sha256_info, np);
534 _ERR("Failed to create sha256_info. Symbolic link is detected");
539 if (!exist(sha256_info)) {
544 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, true)) {
545 _ERR("Failed to create symlink");
551 sql = sqlite3_mprintf(
552 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
553 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
554 if (ret != SQLITE_OK) {
555 _ERR("Sqlite select error");
562 sql = sqlite3_mprintf(
563 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
564 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
565 if (!updateDB(tac_db, sql)) {
566 _ERR("Sqlite update error");
572 } else if (count == 0) {
573 sql = sqlite3_mprintf(
574 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
575 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
576 if (!insertDB(tac_db, sql)) {
577 _ERR("Sqlite insert error");
585 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
586 if (!bf::is_symlink(sha256_info)) {
587 if (compareSHA256Info(sha256_info, np)) {
588 if (copyAssemblyCreateSymlink(binPath, tac_dir, np, false)) {
589 _ERR("Failed to create symlink");
595 char *sql = sqlite3_mprintf(
596 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
597 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
598 if (ret != SQLITE_OK) {
599 _ERR("Sqlite select error");
606 sql = sqlite3_mprintf(
607 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
608 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
609 if (!updateDB(tac_db, sql)) {
610 _ERR("Sqlite update error");
616 } else if (count == 0) {
617 sql = sqlite3_mprintf(
618 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
619 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
620 if (!insertDB(tac_db, sql)) {
621 _ERR("Sqlite insert error");
629 _INFO("Different nuget : %s", np.c_str());
633 _ERR("Failed to create sha256_info. Symbolic link is detected");
639 for (auto& unp : updateTac) {
640 bool isExits = false;
641 for (auto& np : tacDB) {
642 if (!strcmp(unp.c_str(), np.c_str())) {
648 char *sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q AND NUGET = %Q;", pkgId, unp.c_str());
649 if (!deleteDB(tac_db, sql)) {
650 _ERR("Sqlite delete error");
658 tac_updateDB(tac_db);
662 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
663 if (!createDir(tlcDir)) {
664 _ERR("Cannot create directory: %s", tlcDir.c_str());
668 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
670 _ERR("Sqlite create error. So restore the database.");
671 if (tlc_restoreDB() != TAC_ERROR_NONE) {
672 _ERR("Sqlite create error");
675 tlc_db = createDB(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
677 _ERR("Sqlite create error");
681 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
683 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
684 std::vector<std::string> updateTlc = selectDB(tlc_db, sql);
687 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
688 if (!deleteDB(tlc_db, sql)) {
689 _ERR("Sqlite delete error");
695 std::vector<std::string> librariesInfo;
697 librariesInfo = getLibrariesInfo(rootPath);
700 copyLibraryCreateSymlink(pkgId, librariesInfo, tlcDir);
702 tlc_updateDB(tlc_db, updateTlc, tlcDir);
707 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
709 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNINSTALL =====]");
710 _INFO("PackageID : %s", pkgId);
712 // Can be multiple apps in one package
713 if (tacPluginInstalled) {
714 _INFO("TAC plugin already uninstalled");
717 tacPluginInstalled = true;
719 status = "uninstall";
720 tac_db = openDB(TAC_APP_LIST_DB);
722 _ERR("Sqlite open error. So restore the database.");
723 if (tac_restoreDB() != TAC_ERROR_NONE) {
724 _ERR("Sqlite open error");
727 tac_db = openDB(TAC_APP_LIST_DB);
729 _ERR("Sqlite open error");
733 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
735 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
736 updateTac = selectDB(tac_db, sql);
739 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
741 if (!deleteDB(tac_db, sql)) {
742 _ERR("Sqlite delete error");
749 tac_updateDB(tac_db);
752 tlc_db = openDB(TLC_APP_LIST_DB);
754 _ERR("Sqlite open error. So restore the database.");
755 if (tlc_restoreDB() != TAC_ERROR_NONE) {
756 _ERR("Sqlite open error");
759 tlc_db = openDB(TLC_APP_LIST_DB);
761 _ERR("Sqlite open error");
765 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
767 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
768 std::vector<std::string> updateTlc = selectDB(tlc_db, sql);
771 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
772 if (!deleteDB(tlc_db, sql)) {
773 _ERR("Sqlite delete error");
779 tlc_updateDB(tlc_db, updateTlc, concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR));
784 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
786 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_REMOVED =====]");
787 _INFO("PackageID : %s", pkgId);
791 return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
794 void undoStep(std::string tac)
796 std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
798 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
799 std::string bck_path = bck.path().string();
800 if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
801 if (!moveFile(bck_path, bck_path.substr(0, bck_path.rfind(".bck")))) {
802 _ERR("Failed to move %s", bck_path.c_str());
807 } catch (const bf::filesystem_error& error) {
808 _ERR("Failed to recursive directory: %s", error.what());
813 auto convert = [](const std::string& path, const std::string& filename) {
814 if (filename.rfind(".bck") != std::string::npos) {
815 if (!moveFile(path, replaceAll(path, ".bck", ""))) {
816 _ERR("Failed to move %s", path.c_str());
821 scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
826 for (auto& cd : createDirectories) {
827 if (!removeAll(cd)) {
828 _ERR("Failed to remove of %s", cd.c_str());
832 for (auto& cl : createLibraries) {
833 if (!removeFile(cl)) {
834 _ERR("Failed to remove of %s", cl.c_str());
839 void unInstall_Undo()
841 for (auto& unp : updateTac) {
849 if (!tacDB.empty()) {
850 for (auto& np : tacDB) {
857 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)
859 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNDO =====]");
860 _INFO("PackageID : %s", pkgId);
862 // Can be multiple apps in one package
863 if (tacPluginFinished) {
864 _INFO("TAC plugin already finished(UNDO)");
867 tacPluginFinished = true;
869 if (!strcmp("install", status.c_str())) {
871 } else if (!strcmp("update", status.c_str())) {
873 } else if (!strcmp("uninstall", status.c_str())) {
875 } else if (!strcmp("restore", status.c_str())) {
892 void cleanStep(std::string tac)
894 std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
896 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
897 std::string bck_path = bck.path().string();
898 if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
899 if (!removeAll(bck_path)) {
900 _ERR("Failed to remove of %s", bck_path.c_str());
906 bool isExist = false;
907 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
908 std::string bck_path = bck.path().string();
909 if (exist(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
915 if (!removeAll(current_tac)) {
916 _ERR("Failed to remove of %s", current_tac.c_str());
919 } catch (const bf::filesystem_error& error) {
920 _ERR("Failed to recursive directory: %s", error.what());
925 auto convert = [](const std::string& path, const std::string& filename) {
926 if (filename.rfind(".bck") != std::string::npos) {
927 if (!removeFile(path)) {
928 _ERR("Failed to remove of %s", path.c_str());
933 scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
941 void unInstall_Clean()
943 for (auto& unp : updateTac) {
950 if (!tacDB.empty()) {
951 for (auto& np : tacDB) {
958 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
960 if (!strcmp("restore", status.c_str())) {
961 disableTACPackage(pkgId);
963 std::string rootPath = getRootPath(std::string(pkgId));
964 if (!rootPath.empty()) {
965 std::string binPath = concatPath(rootPath, "bin");
966 removeAll(concatPath(binPath, TAC_SYMLINK_SUB_DIR));
969 std::string runtimesDir = concatPath(rootPath, "bin/runtimes");
970 if (exist(runtimesDir)) {
972 sprintf(buffer, "(tizen|linux|unix|base|any)(.\\d.\\d.\\d)?(-%s)?", ARCHITECTURE_IDENTIFIER);
973 std::regex pattern(buffer);
976 for (auto& path : bf::recursive_directory_iterator(runtimesDir)) {
977 std::string symPath = path.path().string();
978 if (isDirectory(symPath) || !bf::is_symlink(symPath))
980 std::string targetDir = symPath.substr(symPath.rfind("/runtimes/") + 10);
981 if (!std::regex_match(targetDir.substr(0, targetDir.find('/')), pattern))
983 if (symPath.rfind(".so") == std::string::npos)
985 copyFile(bf::read_symlink(symPath).string(), symPath);
987 } catch (const bf::filesystem_error& error) {
988 _ERR("Failed to recursive directory: %s", error.what());
992 return PKGMGR_MDPARSER_PLUGIN_UNDO(pkgId, appId, list);
995 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_CLEAN =====]");
996 _INFO("PackageID : %s", pkgId);
998 // Can be multiple apps in one package
999 if (tacPluginFinished) {
1000 _INFO("TAC plugin already finished(CLEAN)");
1003 tacPluginFinished = true;
1005 if (!strcmp("install", status.c_str())) {
1007 } else if (!strcmp("update", status.c_str())) {
1009 } else if (!strcmp("uninstall", status.c_str())) {