- _DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
- _INFO("PackageID : %s", pkgId);
-
- // Can be multiple apps in one package
- if (tacPluginInstalled) {
- _INFO("TAC plugin already upgraded");
- return 0;
- }
- tacPluginInstalled = true;
-
- std::string appType = getAppType(std::string(pkgId));
- if (strstr(appType.c_str(), "dotnet") == NULL) {
- _ERR("App type is not dotnet");
- return 0;
- }
- std::string execName = getExecName(std::string(pkgId));
- std::string rootPath = getRootPath(std::string(pkgId));
- if (execName.empty() || rootPath.empty()) {
- return 0;
- }
- std::string binPath = concatPath(rootPath, "bin");
-
- if (!strcmp("removed", status.c_str())) {
- _INFO("Skipped to parse of deps.json");
- } else {
- std::string metaValue = getMetadataValue(std::string(pkgId), TAC_METADATA_KEY);
- if (metaValue.empty()) {
- return 0;
- }
- if (metaValue == METADATA_VALUE) {
- checkDepsJson(rootPath, binPath, execName);
- }
- }
-
- status = "update";
- tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
- if (!tac_db) {
- _ERR("Sqlite create error. So restore the database.");
- if (tac_restoreDB() != TAC_ERROR_NONE) {
- _ERR("Sqlite create error");
- return -1;
- }
- tac_db = createDB(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
- if (!tac_db) {
- _ERR("Sqlite create error");
- return -1;
- }
- }
- sqlite3_exec(tac_db, "BEGIN;", NULL, NULL, NULL);
-
- char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
- updateTac = selectDB(tac_db, sql);
- sqlite3_free(sql);
-
- bool skipTLC = false;
- if (tacDB.empty()) {
- sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
- if (!deleteDB(tac_db, sql)) {
- _ERR("Sqlite delete error");
- sqlite3_free(sql);
- return -1;
- }
- sqlite3_free(sql);
-
- tac_updateDB(tac_db);
-
- skipTLC = true;
- } else {
- std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
- if (!createDir(tac_dir)) {
- _ERR("Cannot create directory: %s", tac_dir.c_str());
- return 0;
- }
- copySmackAndOwnership(binPath.c_str(), tac_dir.c_str());
-
- for (auto& np : tacDB) {
- std::string tac_name = np.substr(0, np.find('/'));
- std::string tac_version = np.substr(np.rfind('/') + 1);
- _INFO("TAC name : %s", tac_name.c_str());
- _INFO("TAC version : %s", tac_version.c_str());
-
- std::string tac_version_dir = concatPath(__DOTNET_DIR, np);
- std::string sha256_info = concatPath(tac_version_dir, TAC_SHA_256_INFO);
- if (!exist(tac_version_dir)) {
- _INFO("Create tac_version_dir [%s]", tac_version_dir.c_str());
- if (!createDir(tac_version_dir)) {
- _ERR("Cannot create directory: %s", tac_version_dir.c_str());
- status = "restore";
- return -1;
- }
- createDirectories.push_back(tac_version_dir);
- if (!bf::is_symlink(sha256_info)) {
- createSHA256Info(sha256_info, np);
- } else {
- _ERR("Failed to create sha256_info. Symbolic link is detected");
- status = "restore";
- return -1;
- }
-
- if (!exist(sha256_info)) {
- status = "restore";
- return -1;
- }
-
- if (copyAssemblyCreateSymlink(binPath, tac_dir, np, true)) {
- _ERR("Failed to create symlink");
- status = "restore";
- return -1;
- }
-
- int count = -1;
- sql = sqlite3_mprintf(
- "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
- int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
- if (ret != SQLITE_OK) {
- _ERR("Sqlite select error");
- sqlite3_free(sql);
- status = "restore";
- return -1;
- }
- sqlite3_free(sql);
- if (count == 1) {
- sql = sqlite3_mprintf(
- "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
- tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
- if (!updateDB(tac_db, sql)) {
- _ERR("Sqlite update error");
- sqlite3_free(sql);
- status = "restore";
- return -1;
- }
- sqlite3_free(sql);
- } else if (count == 0) {
- sql = sqlite3_mprintf(
- "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
- "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
- if (!insertDB(tac_db, sql)) {
- _ERR("Sqlite insert error");
- sqlite3_free(sql);
- status = "restore";
- return -1;
- }
- sqlite3_free(sql);
- }
- } else {
- _INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
- if (!bf::is_symlink(sha256_info)) {
- if (compareSHA256Info(sha256_info, np)) {
- if (copyAssemblyCreateSymlink(binPath, tac_dir, np, false)) {
- _ERR("Failed to create symlink");
- status = "restore";
- return -1;
- }
-
- int count = -1;
- char *sql = sqlite3_mprintf(
- "SELECT COUNT(NUGET) FROM TAC WHERE PKGID = %Q AND NAME = %Q;", pkgId, tac_name.c_str());
- int ret = sqlite3_exec(tac_db, sql, sqliteCb, &count, NULL);
- if (ret != SQLITE_OK) {
- _ERR("Sqlite select error");
- sqlite3_free(sql);
- status = "restore";
- return -1;
- }
- sqlite3_free(sql);
- if (count == 1) {
- sql = sqlite3_mprintf(
- "UPDATE TAC SET NAME = %Q, VERSION = %Q, NUGET = %Q WHERE PKGID = %Q AND NAME = %Q;",
- tac_name.c_str(), tac_version.c_str(), np.c_str(), pkgId, tac_name.c_str());
- if (!updateDB(tac_db, sql)) {
- _ERR("Sqlite update error");
- sqlite3_free(sql);
- status = "restore";
- return -1;
- }
- sqlite3_free(sql);
- } else if (count == 0) {
- sql = sqlite3_mprintf(
- "INSERT INTO TAC (PKGID, NUGET, NAME, VERSION) " \
- "VALUES (%Q, %Q, %Q, %Q);", pkgId, np.c_str(), tac_name.c_str(), tac_version.c_str());
- if (!insertDB(tac_db, sql)) {
- _ERR("Sqlite insert error");
- sqlite3_free(sql);
- status = "restore";
- return -1;
- }
- sqlite3_free(sql);
- }
- } else {
- _INFO("Different nuget : %s", np.c_str());
- continue;
- }
- } else {
- _ERR("Failed to create sha256_info. Symbolic link is detected");
- status = "restore";
- return -1;
- }
- }
- }
- for (auto& unp : updateTac) {
- bool isExits = false;
- for (auto& np : tacDB) {
- if (!strcmp(unp.c_str(), np.c_str())) {
- isExits = true;
- break;
- }
- }
- if (!isExits) {
- char *sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q AND NUGET = %Q;", pkgId, unp.c_str());
- if (!deleteDB(tac_db, sql)) {
- _ERR("Sqlite delete error");
- sqlite3_free(sql);
- status = "restore";
- return -1;
- }
- sqlite3_free(sql);
- }
- }
- tac_updateDB(tac_db);
- }
-
- ///// TLC /////
- std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
- if (!createDir(tlcDir)) {
- _ERR("Cannot create directory: %s", tlcDir.c_str());