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, 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");
237 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
240 _INFO("Not exist data for TAC in %s", pkgId);
244 for (auto& np : tacDB) {
245 std::string tac_name = np.substr(0, np.find('/'));
246 std::string tac_version = np.substr(np.rfind('/') + 1);
247 _INFO("TAC name : %s", tac_name.c_str());
248 _INFO("TAC version : %s", tac_version.c_str());
250 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
251 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
252 if (!bf::exists(tac_version_dir)) {
253 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
254 if (!createDir(tac_version_dir)) {
255 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
258 createDirectories.push_back(tac_version_dir);
259 if (!bf::is_symlink(sha256_info)) {
260 createSHA256Info(sha256_info, np);
262 _ERR("Failed to create sha256_info. Symbolic link is detected");
266 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, true) < 0) {
267 _ERR("Failed to create symlink");
271 char *sql = sqlite3_mprintf(
272 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
273 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
274 dbInsert(tac_db, sql);
277 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
278 if (!bf::is_symlink(sha256_info)) {
279 if (compareSHA256Info(sha256_info, np)) {
280 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, false) < 0) {
281 _ERR("Failed to create symlink");
285 char *sql = sqlite3_mprintf(
286 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
287 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
288 dbInsert(tac_db, sql);
291 _INFO("Different nuget : %s", np.c_str());
294 _ERR("Failed to create sha256_info. Symbolic link is detected");
298 if (!bf::exists(sha256_info)) {
299 if (!removeAll(tac_version_dir)) {
300 _ERR("Failed to remove of %s", tac_version_dir.c_str());
306 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
307 if (!createDir(tlcDir)) {
308 _ERR("Cannot create directory: %s", tlcDir.c_str());
312 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
314 _ERR("Sqlite create error. So restore the database.");
315 if (restoreTLCDB() != TAC_ERROR_NONE) {
316 _ERR("Sqlite create error");
319 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
321 _ERR("Sqlite create error");
325 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
327 copyNCreateTlcSymlink(pkgId, getLibrariesInfo(rootPath), tlcDir);
332 static int sqliteCb(void *count, int argc, char **argv, char **colName)
334 int *c = (int*)count;
339 static int updateTacDB(sqlite3 *sqlite)
341 for (auto& unp : updateTac) {
343 char *sql = sqlite3_mprintf("SELECT COUNT(NUGET) FROM TAC WHERE NUGET = %Q;", unp.c_str());
344 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
345 if (ret != SQLITE_OK) {
346 _ERR("Sqlite select error");
351 std::string tac_version_dir_prev = concatPath(__DOTNET_DIR, unp);
352 std::string tac_version_dir_backup = tac_version_dir_prev + ".bck";
353 if (!copyDir(tac_version_dir_prev, tac_version_dir_backup)) {
354 _ERR("Failed to copy of %s to %s", tac_version_dir_prev.c_str(), tac_version_dir_backup.c_str());
358 if (!removeAll(tac_version_dir_prev)) {
359 _ERR("Failed to remove of %s", tac_version_dir_prev.c_str());
369 static void updateTlcDB(sqlite3 *sqlite, std::vector<std::string> updateTlc, std::string tlcDir)
371 for (auto& ulp : updateTlc) {
373 char *sql = sqlite3_mprintf("SELECT COUNT(LIBRARY) FROM TLC WHERE LIBRARY = %Q;", ulp.c_str());
374 int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
375 if (ret != SQLITE_OK) {
376 _ERR("Sqlite select error");
381 std::string library_prev = concatPath(tlcDir, ulp);
382 std::string library_backup = library_prev + ".bck";
383 if (!copyFile(library_prev, library_backup)) {
384 _ERR("Failed to copy of %s", library_prev.c_str());
388 if (!removeFile(library_prev)) {
389 _ERR("Failed to remove of %s", library_prev.c_str());
398 extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
400 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
401 _INFO("PackageID : %s", pkgId);
403 // Can be multiple apps in one package
404 if (tacPluginInstalled) {
405 _INFO("TAC plugin already upgraded");
408 tacPluginInstalled = true;
410 std::string appType = getAppType(std::string(pkgId));
411 if (strstr(appType.c_str(), "dotnet") == NULL) {
412 _ERR("App type is not dotnet");
415 std::string execName = getExecName(std::string(pkgId));
416 std::string rootPath = getRootPath(std::string(pkgId));
417 if (execName.empty() || rootPath.empty()) {
420 std::string binPath = concatPath(rootPath, "bin");
422 if (!strcmp("removed", status.c_str())) {
423 _INFO("Skipped to parse of deps.json");
425 std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
426 if (metaValue.empty()) {
429 if (metaValue == METADATA_VALUE) {
430 depsJsonCheck(rootPath, binPath, execName);
435 tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
437 _ERR("Sqlite create error. So restore the database.");
438 if (restoreTACDB() != TAC_ERROR_NONE) {
439 _ERR("Sqlite create error");
442 tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
444 _ERR("Sqlite create error");
448 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
450 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
451 updateTac = dbSelect(tac_db, sql);
454 bool skipTLC = false;
456 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
457 dbDelete(tac_db, sql);
459 if (updateTacDB(tac_db) < 0) {
463 _INFO("Not exist data for TAC in %s", pkgId);
465 for (auto& np : tacDB) {
466 std::string tac_name = np.substr(0, np.find('/'));
467 std::string tac_version = np.substr(np.rfind('/') + 1);
468 _INFO("TAC name : %s", tac_name.c_str());
469 _INFO("TAC version : %s", tac_version.c_str());
471 std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
472 std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
473 if (!bf::exists(tac_version_dir)) {
474 _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
475 if (!createDir(tac_version_dir)) {
476 _ERR("Cannot create directory: %s", tac_version_dir.c_str());
479 createDirectories.push_back(tac_version_dir);
480 if (!bf::is_symlink(sha256_info)) {
481 createSHA256Info(sha256_info, np);
483 _ERR("Failed to create sha256_info. Symbolic link is detected");
487 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, true) < 0) {
488 _ERR("Failed to create symlink");
493 sql = sqlite3_mprintf(
494 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
495 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
496 if (ret != SQLITE_OK) {
497 _ERR("Sqlite select error");
503 sql = sqlite3_mprintf(
504 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
505 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
506 dbUpdate(tac_db, sql);
508 } else if (count == 0) {
509 sql = sqlite3_mprintf(
510 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
511 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
512 dbInsert(tac_db, sql);
516 _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
517 if (!bf::is_symlink(sha256_info)) {
518 if (compareSHA256Info(sha256_info, np)) {
519 if (copyNCreateTacSymlink(binPath, tac_version_dir, np, false) < 0) {
520 _ERR("Failed to create symlink");
525 char *sql = sqlite3_mprintf(
526 "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
527 int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
528 if (ret != SQLITE_OK) {
529 _ERR("Sqlite select error");
535 sql = sqlite3_mprintf(
536 "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
537 tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
538 dbUpdate(tac_db, sql);
540 } else if (count == 0) {
541 sql = sqlite3_mprintf(
542 "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
543 "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
544 dbInsert(tac_db, sql);
548 _INFO("Different nuget : %s", np.c_str());
551 _ERR("Failed to create sha256_info. Symbolic link is detected");
555 if (!bf::exists(sha256_info)) {
556 if (!removeAll(tac_version_dir)) {
557 _ERR("Failed to remove of %s", tac_version_dir.c_str());
561 for (auto& unp : updateTac) {
562 bool isExits = false;
563 for (auto& np : tacDB) {
564 if (!strcmp(unp.c_str(), np.c_str())) {
570 char *sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q AND NUGET = %Q;", pkgId, unp.c_str());
571 dbDelete(tac_db, sql);
575 if (updateTacDB(tac_db) < 0) {
581 std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
582 if (!createDir(tlcDir)) {
583 _ERR("Cannot create directory: %s", tlcDir.c_str());
587 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
589 _ERR("Sqlite create error. So restore the database.");
590 if (restoreTLCDB() != TAC_ERROR_NONE) {
591 _ERR("Sqlite create error");
594 tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
596 _ERR("Sqlite create error");
600 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
602 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
603 std::vector<std::string> updateTlc = dbSelect(tlc_db, sql);
606 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
607 dbDelete(tlc_db, sql);
610 std::vector<std::string> librariesInfo = getLibrariesInfo(rootPath);
612 librariesInfo.clear();
615 copyNCreateTlcSymlink(pkgId, librariesInfo, tlcDir);
617 updateTlcDB(tlc_db, updateTlc, tlcDir);
622 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgId, const char *appId, GList *list)
624 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNINSTALL =====]");
625 _INFO("PackageID : %s", pkgId);
627 // Can be multiple apps in one package
628 if (tacPluginInstalled) {
629 _INFO("TAC plugin already uninstalled");
632 tacPluginInstalled = true;
634 status = "uninstall";
635 tac_db = dbOpen(TAC_APP_LIST_DB);
637 _ERR("Sqlite open error. So restore the database.");
638 if (restoreTACDB() != TAC_ERROR_NONE) {
639 _ERR("Sqlite open error");
642 tac_db = dbOpen(TAC_APP_LIST_DB);
644 _ERR("Sqlite open error");
648 sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
650 char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
651 updateTac = dbSelect(tac_db, sql);
654 sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
655 dbDelete(tac_db, sql);
658 if (updateTacDB(tac_db) < 0) {
663 tlc_db = dbOpen(TLC_APP_LIST_DB);
665 _ERR("Sqlite open error. So restore the database.");
666 if (restoreTLCDB() != TAC_ERROR_NONE) {
667 _ERR("Sqlite open error");
670 tlc_db = dbOpen(TLC_APP_LIST_DB);
672 _ERR("Sqlite open error");
676 sqlite3_exec(tlc_db, "BEGIN;", NULL, NULL, NULL);
678 sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
679 std::vector<std::string> updateTlc = dbSelect(tlc_db, sql);
682 sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
683 dbDelete(tlc_db, sql);
686 updateTlcDB(tlc_db, updateTlc, concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR));
691 extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *appId, GList *list)
693 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_REMOVED =====]");
694 _INFO("PackageID : %s", pkgId);
698 return PKGMGR_MDPARSER_PLUGIN_UPGRADE(pkgId, appId, list);
701 void cleanStep(std::string tac)
703 std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
705 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
706 std::string bck_path = bck.path().string();
707 if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
708 if (!removeAll(bck_path)) {
709 _ERR("Failed to remove of %s", bck_path.c_str());
715 bool isExist = false;
716 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
717 std::string bck_path = bck.path().string();
718 if (bf::exists(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
724 if (!removeAll(current_tac)) {
725 _ERR("Failed to remove of %s", current_tac.c_str());
728 } catch (const bf::filesystem_error& error) {
729 _ERR("Failed to recursive directory: %s", error.what());
734 auto convert = [](const std::string& path, const std::string& filename) {
735 if (filename.rfind(".bck") != std::string::npos) {
736 if (!removeFile(path)) {
737 _ERR("Failed to remove of %s", path.c_str());
742 scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
750 void unInstall_Clean()
752 for (auto& unp : updateTac) {
759 if (!tacDB.empty()) {
760 for (auto& np : tacDB) {
767 extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId, GList *list)
769 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_CLEAN =====]");
770 _INFO("PackageID : %s", pkgId);
772 // Can be multiple apps in one package
773 if (tacPluginFinished) {
774 _INFO("TAC plugin already finished(CLEAN)");
777 tacPluginFinished = true;
779 if (!strcmp("install", status.c_str())) {
781 } else if (!strcmp("update", status.c_str())) {
783 } else if (!strcmp("uninstall", status.c_str())) {
800 void undoStep(std::string tac)
802 std::string current_tac = concatPath(__DOTNET_DIR, tac.substr(0, tac.find('/')));
804 for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
805 std::string bck_path = bck.path().string();
806 if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
807 if (!moveFile(bck_path, bck_path.substr(0, bck_path.rfind(".bck")))) {
808 _ERR("Failed to move %s", bck_path.c_str());
813 } catch (const bf::filesystem_error& error) {
814 _ERR("Failed to recursive directory: %s", error.what());
819 auto convert = [](const std::string& path, const std::string& filename) {
820 if (filename.rfind(".bck") != std::string::npos) {
821 if (!moveFile(path, replaceAll(path, ".bck", ""))) {
822 _ERR("Failed to move %s", path.c_str());
827 scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
832 for (auto& cd : createDirectories) {
833 if (!removeAll(cd)) {
834 _ERR("Failed to remove of %s", cd.c_str());
838 for (auto& cl : createLibraries) {
839 if (!removeFile(cl)) {
840 _ERR("Failed to remove of %s", cl.c_str());
845 void unInstall_Undo()
847 for (auto& unp : updateTac) {
855 if (!tacDB.empty()) {
856 for (auto& np : tacDB) {
863 extern "C" int PKGMGR_MDPARSER_PLUGIN_UNDO(const char *pkgId, const char *appId, GList *list)
865 _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UNDO =====]");
866 _INFO("PackageID : %s", pkgId);
868 // Can be multiple apps in one package
869 if (tacPluginFinished) {
870 _INFO("TAC plugin already finished(UNDO)");
873 tacPluginFinished = true;
875 if (!strcmp("install", status.c_str())) {
877 } else if (!strcmp("update", status.c_str())) {
879 } else if (!strcmp("uninstall", status.c_str())) {