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"
26 #include <boost/filesystem.hpp>
28 #include <json/json.h>
29 #include <pkgmgr-info.h>
34 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
37 #define __STR(x) __XSTR(x)
38 static const char* __DOTNET_DIR = __STR(DOTNET_DIR);
42 std::vector<std::string> nugetPackagesAssembliesSha;
43 std::vector<std::string> tacDB;
44 std::vector<std::string> createDirectories;
45 std::vector<std::string> createLibraries;
46 std::vector<std::string> updateTac;
47 std::string status = "";
48 static sqlite3 *tac_db = NULL;
49 static sqlite3 *tlc_db = NULL;
50 bool tacPluginInstalled = false;
51 bool tacPluginFinished = false;
53 static void createSHA256Info(std::string sha256Info, std::string nugetPackage)
55 std::ofstream ofs(sha256Info, std::ios::app);
56 int assembly_count = 0;
57 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
58 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
59 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
60 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
61 std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
62 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
63 ofs << assembly << ":" << sha << std::endl;
67 ofs << assembly_count << std::endl;
71 static bool compareSHA256Info(std::string sha256Info, std::string nugetPackage)
73 int compare_count = 0;
74 int assembly_count = 0;
75 std::string sha256_count = "0";
76 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
77 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
78 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
79 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
80 std::string sha = npAssemblySha.substr(npAssemblySha.rfind(':') + 1);
81 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
83 std::ifstream ifs(sha256Info);
86 while (getline(ifs, get_str)) {
87 if (!strcmp(get_str.c_str(), (assembly + ":" + sha).c_str())) {
90 sha256_count = get_str;
96 if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
97 !strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
98 _INFO("Same nuget : %s", nugetPackage.c_str());
104 static int copyNCreateTacSymlink(std::string binPath, std::string tacVersionDir, std::string nugetPackage, bool isCreateTacDir)
106 std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
107 if (!createDir(tac_dir)) {
108 _ERR("Cannot create directory: %s", tac_dir.c_str());
112 for (auto& npAssemblySha : nugetPackagesAssembliesSha) {
113 std::string nuget_package_assembly = npAssemblySha.substr(0, npAssemblySha.rfind(':'));
114 std::string nuget_package = nuget_package_assembly.substr(0, nuget_package_assembly.rfind(':'));
115 std::string assembly = nuget_package_assembly.substr(nuget_package_assembly.rfind(':') + 1);
116 if (!strcmp(nuget_package.c_str(), nugetPackage.c_str())) {
117 if (bf::exists(concatPath(binPath, assembly))) {
118 if (isCreateTacDir) {
119 if (!copyFile(concatPath(binPath, assembly), concatPath(tacVersionDir, assembly))) {
120 _ERR("Failed to copy of %s", assembly.c_str());
124 bf::create_symlink(concatPath(tacVersionDir, assembly), concatPath(tac_dir, assembly));
125 if (!removeFile(concatPath(binPath, assembly))) {
126 _ERR("Failed to remove of %s", assembly.c_str());
135 static void copyNCreateTlcSymlink(const char* pkgId, std::vector<std::string> LibrariesInfo, std::string tlcDir)
137 if (LibrariesInfo.empty()) {
138 _INFO("Not exist data for TLC in %s", pkgId);
142 for (auto& librarySha : LibrariesInfo) {
143 std::string library = librarySha.substr(0, librarySha.find(':'));
144 std::string filename = library.substr(library.rfind('/') + 1);
145 std::string fileSha = filename + ".." + librarySha.substr(librarySha.find(':') + 1);
146 bool fileCopied = false;
147 if (!bf::exists(concatPath(tlcDir, fileSha))) {
148 if (!copyFile(library, concatPath(tlcDir, fileSha))) {
149 _ERR("Failed to copy of %s", filename.c_str());
153 createLibraries.push_back(concatPath(tlcDir, fileSha));
155 if (!removeFile(library)) {
156 _ERR("Failed to remove of %s", library.c_str());
158 removeFile(concatPath(tlcDir, fileSha));
162 bf::create_symlink(concatPath(tlcDir, fileSha), library);
164 char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
165 if (!dbInsert(tlc_db, TLC_APP_LIST_DB, sql)) {
166 _ERR("Sqlite insert error");
168 copyFile(concatPath(tlcDir, fileSha), library);
170 removeFile(concatPath(tlcDir, fileSha));
178 static void depsJsonCheck(std::string rootPath, std::string binPath, std::string execName)
180 for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
181 std::string nuget_package = npAssembly.substr(0, npAssembly.rfind(':'));
182 std::string assembly_name = npAssembly.substr(npAssembly.rfind(':') + 1);
183 tacDB.push_back(nuget_package);
184 std::string buffer = SHA256(concatPath(binPath, assembly_name));
185 nugetPackagesAssembliesSha.push_back(nuget_package + ":" + assembly_name + ":" + buffer);
186 _INFO("Assembly : [%s] / SHA256 : [%s]", assembly_name.c_str(), buffer.c_str());
188 std::sort(tacDB.begin(), tacDB.end());
189 tacDB.erase(unique(tacDB.begin(), tacDB.end()), tacDB.end());
192 extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
194 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_INSTALL =====]");
195 _INFO("PackageID : %s", pkgId);
197 // Can be multiple apps in one package
198 if (tacPluginInstalled) {
199 _INFO("TAC plugin already installed");
202 tacPluginInstalled = true;
204 std::string appType = getAppType(std::string(pkgId));
205 if (strstr(appType.c_str(), "dotnet") == NULL) {
206 _ERR("App type is not dotnet");
209 std::string execName = getExecName(std::string(pkgId));
210 std::string rootPath = getRootPath(std::string(pkgId));
211 if (execName.empty() || rootPath.empty()) {
214 std::string binPath = concatPath(rootPath, "bin");
215 std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
216 if (metaValue.empty()) {
219 if (metaValue == METADATA_VALUE) {
220 depsJsonCheck(rootPath, binPath, execName);
224 tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
226 _ERR("Sqlite create error. So restore the database.");
227 if (restoreTACDB() != TAC_ERROR_NONE) {
228 _ERR("Sqlite create error");
231 tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
233 _ERR("Sqlite create error");
239 _INFO("Not exist data for TAC in %s", pkgId);
243 for (auto& np : tacDB) {
244 std::string tac_name = np.substr(0, np.find('/'));
245 std::string tac_version = np.substr(np.rfind('/') + 1);
246 _INFO("TAC name : %s", tac_name.c_str());
247 _INFO("TAC version : %s", tac_version.c_str());
249 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
250 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
251 if (!bf::exists(tac_version_dir)) {
252 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
253 if (!createDir(tac_version_dir)) {
254 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
257 createDirectories.push_back(tac_version_dir);
258 if (!bf::is_symlink(sha256_info)) {
259 createSHA256Info(sha256_info, np);
261 _ERR("Failed to create sha256_info. Symbolic link is detected");
265 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, true) < 0) {
266 _ERR("Failed to create symlink");
270 char *sql = sqlite3_mprintf(
271 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
272 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
273 dbInsert(tac_db, TAC_APP_LIST_DB, sql);
276 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
277 if (!bf::is_symlink(sha256_info)) {
278 if (compareSHA256Info(sha256_info, np)) {
279 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, false) < 0) {
280 _ERR("Failed to create symlink");
284 char *sql = sqlite3_mprintf(
285 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
286 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
287 dbInsert(tac_db, TAC_APP_LIST_DB, sql);
290 _INFO("Different nuget : %s", np.c_str());
293 _ERR("Failed to create sha256_info. Symbolic link is detected");
297 if (!bf::exists(sha256_info)) {
298 if (!removeAll(tac_version_dir)) {
299 _ERR("Failed to remove of %s", tac_version_dir.c_str());
305 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
306 if (!createDir(tlcDir)) {
307 _ERR("Cannot create directory: %s", tlcDir.c_str());
311 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
313 _ERR("Sqlite create error. So restore the database.");
314 if (restoreTLCDB() != TAC_ERROR_NONE) {
315 _ERR("Sqlite create error");
318 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
320 _ERR("Sqlite create error");
325 copyNCreateTlcSymlink(pkgId, getLibrariesInfo(rootPath), tlcDir);
330 static int sqliteCb(void *count, int argc, char **argv, char **colName)
332 int *c = (int*)count;
337 static int updateTacDB(sqlite3 *sqlite)
339 for (auto& unp : updateTac) {
341 char *sql = sqlite3_mprintf("SELECT COUNT(NUGET) FROM TAC WHERE NUGET = %Q;", unp.c_str());
342 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
343 if (ret != SQLITE_OK) {
344 _ERR("Sqlite select error");
349 std::string tac_version_dir_prev = concatPath(__DOTNET_DIR, unp);
350 std::string tac_version_dir_backup = tac_version_dir_prev + ".bck";
351 if (!copyDir(tac_version_dir_prev, tac_version_dir_backup)) {
352 _ERR("Failed to copy of %s to %s", tac_version_dir_prev.c_str(), tac_version_dir_backup.c_str());
356 if (!removeAll(tac_version_dir_prev)) {
357 _ERR("Failed to remove of %s", tac_version_dir_prev.c_str());
367 static void updateTlcDB(sqlite3 *sqlite, std::vector<std::string> updateTlc, std::string tlcDir)
369 for (auto& ulp : updateTlc) {
371 char *sql = sqlite3_mprintf("SELECT COUNT(LIBRARY) FROM TLC WHERE LIBRARY = %Q;", ulp.c_str());
372 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
373 if (ret != SQLITE_OK) {
374 _ERR("Sqlite select error");
379 std::string library_prev = concatPath(tlcDir, ulp);
380 std::string library_backup = library_prev + ".bck";
381 if (!copyFile(library_prev, library_backup)) {
382 _ERR("Failed to copy of %s", library_prev.c_str());
386 if (!removeFile(library_prev)) {
387 _ERR("Failed to remove of %s", library_prev.c_str());
396 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
398 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
399 _INFO("PackageID : %s", pkgId);
401 // Can be multiple apps in one package
402 if (tacPluginInstalled) {
403 _INFO("TAC plugin already upgraded");
406 tacPluginInstalled = true;
408 std::string appType = getAppType(std::string(pkgId));
409 if (strstr(appType.c_str(), "dotnet") == NULL) {
410 _ERR("App type is not dotnet");
413 std::string execName = getExecName(std::string(pkgId));
414 std::string rootPath = getRootPath(std::string(pkgId));
415 if (execName.empty() || rootPath.empty()) {
418 std::string binPath = concatPath(rootPath, "bin");
420 if (!strcmp("removed", status.c_str())) {
421 _INFO("Skipped to parse of deps.json");
423 std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
424 if (metaValue.empty()) {
427 if (metaValue == METADATA_VALUE) {
428 depsJsonCheck(rootPath, binPath, execName);
433 tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
435 _ERR("Sqlite create error. So restore the database.");
436 if (restoreTACDB() != TAC_ERROR_NONE) {
437 _ERR("Sqlite create error");
440 tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
442 _ERR("Sqlite create error");
447 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
448 updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
451 bool skipTLC = false;
453 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
454 dbDelete(tac_db, TAC_APP_LIST_DB, sql);
456 if (updateTacDB(tac_db) < 0) {
460 _INFO("Not exist data for TAC in %s", pkgId);
462 for (auto& np : tacDB) {
463 std::string tac_name = np.substr(0, np.find('/'));
464 std::string tac_version = np.substr(np.rfind('/') + 1);
465 _INFO("TAC name : %s", tac_name.c_str());
466 _INFO("TAC version : %s", tac_version.c_str());
468 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
469 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
470 if (!bf::exists(tac_version_dir)) {
471 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
472 if (!createDir(tac_version_dir)) {
473 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
476 createDirectories.push_back(tac_version_dir);
477 if (!bf::is_symlink(sha256_info)) {
478 createSHA256Info(sha256_info, np);
480 _ERR("Failed to create sha256_info. Symbolic link is detected");
484 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, true) < 0) {
485 _ERR("Failed to create symlink");
490 sql = sqlite3_mprintf(
491 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
492 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
493 if (ret != SQLITE_OK) {
494 _ERR("Sqlite select error");
500 sql = sqlite3_mprintf(
501 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
502 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
503 dbUpdate(tac_db, TAC_APP_LIST_DB, sql);
505 } else if (count == 0) {
506 sql = sqlite3_mprintf(
507 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
508 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
509 dbInsert(tac_db, TAC_APP_LIST_DB, sql);
513 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
514 if (!bf::is_symlink(sha256_info)) {
515 if (compareSHA256Info(sha256_info, np)) {
516 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, false) < 0) {
517 _ERR("Failed to create symlink");
522 char *sql = sqlite3_mprintf(
523 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
524 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
525 if (ret != SQLITE_OK) {
526 _ERR("Sqlite select error");
532 sql = sqlite3_mprintf(
533 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
534 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
535 dbUpdate(tac_db, TAC_APP_LIST_DB, sql);
537 } else if (count == 0) {
538 sql = sqlite3_mprintf(
539 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
540 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
541 dbInsert(tac_db, TAC_APP_LIST_DB, sql);
545 _INFO("Different nuget : %s", np.c_str());
548 _ERR("Failed to create sha256_info. Symbolic link is detected");
552 if (!bf::exists(sha256_info)) {
553 if (!removeAll(tac_version_dir)) {
554 _ERR("Failed to remove of %s", tac_version_dir.c_str());
558 for (auto& unp : updateTac) {
559 bool isExits = false;
560 for (auto& np : tacDB) {
561 if (!strcmp(unp.c_str(), np.c_str())) {
567 char *sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q AND NUGET = %Q;", pkgId, unp.c_str());
568 dbDelete(tac_db, TAC_APP_LIST_DB, sql);
572 if (updateTacDB(tac_db) < 0) {
578 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
579 if (!createDir(tlcDir)) {
580 _ERR("Cannot create directory: %s", tlcDir.c_str());
584 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
586 _ERR("Sqlite create error. So restore the database.");
587 if (restoreTLCDB() != TAC_ERROR_NONE) {
588 _ERR("Sqlite create error");
591 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
593 _ERR("Sqlite create error");
598 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
599 std::vector<std::string> updateTlc = dbSelect(tlc_db, TLC_APP_LIST_DB, sql);
602 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
603 dbDelete(tlc_db, TLC_APP_LIST_DB, sql);
606 std::vector<std::string> librariesInfo = getLibrariesInfo(rootPath);
608 librariesInfo.clear();
611 copyNCreateTlcSymlink(pkgId, librariesInfo, tlcDir);
613 updateTlcDB(tlc_db, updateTlc, tlcDir);
618 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
620 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNINSTALL =====]");
621 _INFO("PackageID : %s", pkgId);
623 // Can be multiple apps in one package
624 if (tacPluginInstalled) {
625 _INFO("TAC plugin already uninstalled");
628 tacPluginInstalled = true;
630 status = "uninstall";
631 tac_db = dbOpen(TAC_APP_LIST_DB);
633 _ERR("Sqlite open error. So restore the database.");
634 if (restoreTACDB() != TAC_ERROR_NONE) {
635 _ERR("Sqlite open error");
638 tac_db = dbOpen(TAC_APP_LIST_DB);
640 _ERR("Sqlite open error");
645 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
646 updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
649 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
650 dbDelete(tac_db, TAC_APP_LIST_DB, sql);
653 if (updateTacDB(tac_db) < 0) {
658 tlc_db = dbOpen(TLC_APP_LIST_DB);
660 _ERR("Sqlite open error. So restore the database.");
661 if (restoreTLCDB() != TAC_ERROR_NONE) {
662 _ERR("Sqlite open error");
665 tlc_db = dbOpen(TLC_APP_LIST_DB);
667 _ERR("Sqlite open error");
672 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
673 std::vector<std::string> updateTlc = dbSelect(tlc_db, TLC_APP_LIST_DB, sql);
676 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
677 dbDelete(tlc_db, TLC_APP_LIST_DB, sql);
680 updateTlcDB(tlc_db, updateTlc, concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR));
685 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
687 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_REMOVED =====]");
688 _INFO("PackageID : %s", pkgId);
692 return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
695 void cleanStep(std::string tac)
697 std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
699 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
700 std::string bck_path = bck.path().string();
701 if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
702 if (!removeAll(bck_path)) {
703 _ERR("Failed to remove of %s", bck_path.c_str());
709 bool isExist = false;
710 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
711 std::string bck_path = bck.path().string();
712 if (bf::exists(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
718 if (!removeAll(current_tac)) {
719 _ERR("Failed to remove of %s", current_tac.c_str());
722 } catch (const bf::filesystem_error& error) {
723 _ERR("Failed to recursive directory: %s", error.what());
728 auto convert = [](const std::string& path, const std::string& filename) {
729 if (filename.rfind(".bck") != std::string::npos) {
730 if (!removeFile(path)) {
731 _ERR("Failed to remove of %s", path.c_str());
736 scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
744 void unInstall_Clean()
746 for (auto& unp : updateTac) {
753 if (!tacDB.empty()) {
754 for (auto& np : tacDB) {
761 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
763 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_CLEAN =====]");
764 _INFO("PackageID : %s", pkgId);
766 // Can be multiple apps in one package
767 if (tacPluginFinished) {
768 _INFO("TAC plugin already finished(CLEAN)");
771 tacPluginFinished = true;
773 if (!strcmp("install", status.c_str())) {
775 } else if (!strcmp("update", status.c_str())) {
777 } else if (!strcmp("uninstall", status.c_str())) {
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())) {