#include <glib.h>
#include <json/json.h>
#include <pkgmgr-info.h>
-#include <pkgmgr_installer_info.h>
-#include <openssl/sha.h>
#ifdef LOG_TAG
#undef LOG_TAG
std::vector<std::string> nugetPackagesAssembliesSha;
std::vector<std::string> tacDB;
std::vector<std::string> createDirectories;
+std::vector<std::string> createLibraries;
std::vector<std::string> updateTac;
std::string status = "";
static sqlite3 *tac_db = NULL;
+static sqlite3 *tlc_db = NULL;
bool tacPluginInstalled = false;
bool tacPluginFinished = false;
-static void SHA256(std::string path, char outputBuffer[65])
-{
- FILE *file = fopen(path.c_str(), "rb");
- if (!file) {
- return;
- }
-
- unsigned char hash[SHA256_DIGEST_LENGTH];
- SHA256_CTX sha256;
- SHA256_Init(&sha256);
- int bytesRead = 0;
- const int bufSize = 32768;
- char *buffer = (char*)malloc(bufSize);
- if (!buffer) {
- fclose(file);
- return;
- }
-
- while ((bytesRead = fread(buffer, 1, bufSize, file))) {
- SHA256_Update(&sha256, buffer, bytesRead);
- }
- SHA256_Final(hash, &sha256);
- for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
- snprintf(outputBuffer + (i * 2), 3, "%02x", hash[i]);
- }
- outputBuffer[64] = 0;
-
- fclose(file);
- free(buffer);
-}
-
static void createSHA256Info(std::string sha256Info, std::string nugetPackage)
{
std::ofstream ofs(sha256Info, std::ios::app);
ofs.close();
}
-static int compareSHA256Info(std::string sha256Info, std::string nugetPackage)
+static bool compareSHA256Info(std::string sha256Info, std::string nugetPackage)
{
int compare_count = 0;
int assembly_count = 0;
if (!strcmp(std::to_string(assembly_count).c_str(), std::to_string(compare_count).c_str()) &&
!strcmp(std::to_string(assembly_count).c_str(), sha256_count.c_str())) {
_INFO("Same nuget : %s", nugetPackage.c_str());
- return 1;
+ return true;
}
- return 0;
+ return false;
}
-static int copyNCreateSymlink(std::string binPath, std::string tacVersionDir, std::string nugetPackage, bool isCreateTacDir)
+static int copyNCreateTacSymlink(std::string binPath, std::string tacVersionDir, std::string nugetPackage, bool isCreateTacDir)
{
- uid_t g_uid = 0;
- const gid_t g_gid = 0;
- if (pkgmgr_installer_info_get_target_uid(&g_uid) < 0) {
- _ERR("Failed to get UID");
- return -1;
- }
-
std::string tac_dir = concatPath(binPath, TAC_SYMLINK_SUB_DIR);
if (!createDir(tac_dir)) {
_ERR("Cannot create directory: %s", tac_dir.c_str());
}
}
bf::create_symlink(concatPath(tacVersionDir, assembly), concatPath(tac_dir, assembly));
- if (lchown(concatPath(tac_dir, assembly).c_str(), g_uid, g_gid)) {
- _ERR("Failed to change owner of: %s", concatPath(tac_dir, assembly).c_str());
- return -1;
- }
if (!removeFile(concatPath(binPath, assembly))) {
_ERR("Failed to remove of %s", assembly.c_str());
return -1;
return 0;
}
+static void copyNCreateTlcSymlink(const char* pkgId, std::vector<std::string> LibrariesInfo, std::string tlcDir)
+{
+ if (LibrariesInfo.empty()) {
+ _INFO("Not exist data for TLC in %s", pkgId);
+ return;
+ }
+
+ for (auto& librarySha : LibrariesInfo) {
+ std::string library = librarySha.substr(0, librarySha.find(':'));
+ std::string filename = library.substr(library.rfind('/') + 1);
+ std::string fileSha = filename + ".." + librarySha.substr(librarySha.find(':') + 1);
+ bool fileCopied = false;
+ if (!bf::exists(concatPath(tlcDir, fileSha))) {
+ if (!copyFile(library, concatPath(tlcDir, fileSha))) {
+ _ERR("Failed to copy of %s", filename.c_str());
+ continue;
+ }
+ fileCopied = true;
+ createLibraries.push_back(concatPath(tlcDir, fileSha));
+ }
+ if (!removeFile(library)) {
+ _ERR("Failed to remove of %s", library.c_str());
+ if (fileCopied) {
+ removeFile(concatPath(tlcDir, fileSha));
+ }
+ continue;
+ }
+ bf::create_symlink(concatPath(tlcDir, fileSha), library);
+
+ char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
+ if (!dbInsert(tlc_db, TLC_APP_LIST_DB, sql)) {
+ _ERR("Sqlite insert error");
+ sqlite3_free(sql);
+ copyFile(concatPath(tlcDir, fileSha), library);
+ if (fileCopied) {
+ removeFile(concatPath(tlcDir, fileSha));
+ }
+ continue;
+ }
+ sqlite3_free(sql);
+ }
+}
+
static void depsJsonCheck(std::string rootPath, std::string binPath, std::string execName)
{
for (auto& npAssembly : depsJsonParser(rootPath, execName)) {
std::string nuget_package = npAssembly.substr(0, npAssembly.rfind(':'));
std::string assembly_name = npAssembly.substr(npAssembly.rfind(':') + 1);
tacDB.push_back(nuget_package);
- char buffer[65] = {0};
- SHA256(concatPath(binPath, assembly_name), buffer);
+ std::string buffer = SHA256(concatPath(binPath, assembly_name));
nugetPackagesAssembliesSha.push_back(nuget_package + ":" + assembly_name + ":" + buffer);
- _INFO("Assembly : [%s] / SHA256 : [%s]", assembly_name.c_str(), buffer);
+ _INFO("Assembly : [%s] / SHA256 : [%s]", assembly_name.c_str(), buffer.c_str());
}
std::sort(tacDB.begin(), tacDB.end());
tacDB.erase(unique(tacDB.begin(), tacDB.end()), tacDB.end());
status = "install";
tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
if (!tac_db) {
- _ERR("Sqlite create error");
- return 0;
+ _ERR("Sqlite create error. So restore the database.");
+ if (restoreTACDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
+ tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
+ if (!tac_db) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
}
if (tacDB.empty()) {
return -1;
}
- if (copyNCreateSymlink(binPath, tac_version_dir, np, true) < 0) {
+ if (copyNCreateTacSymlink(binPath, tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
_INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
if (!bf::is_symlink(sha256_info)) {
if (compareSHA256Info(sha256_info, np)) {
- if (copyNCreateSymlink(binPath, tac_version_dir, np, false) < 0) {
+ if (copyNCreateTacSymlink(binPath, tac_version_dir, np, false) < 0) {
_ERR("Failed to create symlink");
return -1;
}
}
}
}
+
+ ///// TLC /////
+ std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
+ if (!createDir(tlcDir)) {
+ _ERR("Cannot create directory: %s", tlcDir.c_str());
+ return 0;
+ }
+
+ tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
+ if (!tlc_db) {
+ _ERR("Sqlite create error. So restore the database.");
+ if (restoreTLCDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
+ tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
+ if (!tlc_db) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
+ }
+
+ copyNCreateTlcSymlink(pkgId, getLibrariesInfo(rootPath), tlcDir);
+
return 0;
}
return 0;
}
+static void updateTlcDB(sqlite3 *sqlite, std::vector<std::string> updateTlc, std::string tlcDir)
+{
+ for (auto& ulp : updateTlc) {
+ int count = -1;
+ char *sql = sqlite3_mprintf("SELECT COUNT(LIBRARY) FROM TLC WHERE LIBRARY = %Q;", ulp.c_str());
+ int ret = sqlite3_exec(sqlite, sql, sqliteCb, &count, NULL);
+ if (ret != SQLITE_OK) {
+ _ERR("Sqlite select error");
+ sqlite3_free(sql);
+ continue;
+ }
+ if (count == 0) {
+ std::string library_prev = concatPath(tlcDir, ulp);
+ std::string library_backup = library_prev + ".bck";
+ if (!copyFile(library_prev, library_backup)) {
+ _ERR("Failed to copy of %s", library_prev.c_str());
+ sqlite3_free(sql);
+ continue;
+ }
+ if (!removeFile(library_prev)) {
+ _ERR("Failed to remove of %s", library_prev.c_str());
+ sqlite3_free(sql);
+ continue;
+ }
+ }
+ sqlite3_free(sql);
+ }
+}
+
extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list)
{
_DBG("[===== PKGMGR_MDPARSER_PLUGIN_UPGRADE =====]");
status = "update";
tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
if (!tac_db) {
- _ERR("Sqlite open error");
- return 0;
+ _ERR("Sqlite create error. So restore the database.");
+ if (restoreTACDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
+ tac_db = dbCreate(TAC_APP_LIST_DB, CREATE_TAC_DB_TABLE);
+ if (!tac_db) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
}
char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
updateTac = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
sqlite3_free(sql);
+ bool skipTLC = false;
if (tacDB.empty()) {
sql = sqlite3_mprintf("DELETE FROM TAC WHERE PKGID = %Q;", pkgId);
dbDelete(tac_db, TAC_APP_LIST_DB, sql);
if (updateTacDB(tac_db) < 0) {
return -1;
}
+ skipTLC = true;
_INFO("Not exist data for TAC in %s", pkgId);
- return 0;
} else {
for (auto& np : tacDB) {
std::string tac_name = np.substr(0, np.find('/'));
return -1;
}
- if (copyNCreateSymlink(binPath, tac_version_dir, np, true) < 0) {
+ if (copyNCreateTacSymlink(binPath, tac_version_dir, np, true) < 0) {
_ERR("Failed to create symlink");
return -1;
}
_INFO("Exists tac_version_dir [%s]", tac_version_dir.c_str());
if (!bf::is_symlink(sha256_info)) {
if (compareSHA256Info(sha256_info, np)) {
- if (copyNCreateSymlink(binPath, tac_version_dir, np, false) < 0) {
+ if (copyNCreateTacSymlink(binPath, tac_version_dir, np, false) < 0) {
_ERR("Failed to create symlink");
return -1;
}
return -1;
}
}
+
+ ///// TLC /////
+ std::string tlcDir = concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR);
+ if (!createDir(tlcDir)) {
+ _ERR("Cannot create directory: %s", tlcDir.c_str());
+ return 0;
+ }
+
+ tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
+ if (!tlc_db) {
+ _ERR("Sqlite create error. So restore the database.");
+ if (restoreTLCDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
+ tlc_db = dbCreate(TLC_APP_LIST_DB, CREATE_TLC_DB_TABLE);
+ if (!tlc_db) {
+ _ERR("Sqlite create error");
+ return 0;
+ }
+ }
+
+ sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
+ std::vector<std::string> updateTlc = dbSelect(tlc_db, TLC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
+
+ sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
+ dbDelete(tlc_db, TLC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
+
+ std::vector<std::string> librariesInfo = getLibrariesInfo(rootPath);
+ if (skipTLC) {
+ librariesInfo.clear();
+ }
+
+ copyNCreateTlcSymlink(pkgId, librariesInfo, tlcDir);
+
+ updateTlcDB(tlc_db, updateTlc, tlcDir);
+
return 0;
}
status = "uninstall";
tac_db = dbOpen(TAC_APP_LIST_DB);
if (!tac_db) {
- _ERR("Sqlite open error");
- return 0;
+ _ERR("Sqlite open error. So restore the database.");
+ if (restoreTACDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite open error");
+ return 0;
+ }
+ tac_db = dbOpen(TAC_APP_LIST_DB);
+ if (!tac_db) {
+ _ERR("Sqlite open error");
+ return 0;
+ }
}
char *sql = sqlite3_mprintf("SELECT * FROM TAC WHERE PKGID = %Q;", pkgId);
if (updateTacDB(tac_db) < 0) {
return -1;
}
+
+ ///// TLC /////
+ tlc_db = dbOpen(TLC_APP_LIST_DB);
+ if (!tlc_db) {
+ _ERR("Sqlite open error. So restore the database.");
+ if (restoreTLCDB() != TAC_ERROR_NONE) {
+ _ERR("Sqlite open error");
+ return 0;
+ }
+ tlc_db = dbOpen(TLC_APP_LIST_DB);
+ if (!tlc_db) {
+ _ERR("Sqlite open error");
+ return 0;
+ }
+ }
+
+ sql = sqlite3_mprintf("SELECT * FROM TLC WHERE PKGID = %Q;", pkgId);
+ std::vector<std::string> updateTlc = dbSelect(tlc_db, TLC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
+
+ sql = sqlite3_mprintf("DELETE FROM TLC WHERE PKGID = %Q;", pkgId);
+ dbDelete(tlc_db, TLC_APP_LIST_DB, sql);
+ sqlite3_free(sql);
+
+ updateTlcDB(tlc_db, updateTlc, concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR));
+
return 0;
}
_ERR("Failed to recursive directory: %s", error.what());
return;
}
+
+ ///// TLC /////
+ auto convert = [](const std::string& path, const std::string& filename) {
+ if (filename.rfind(".bck") != std::string::npos) {
+ if (!removeFile(path)) {
+ _ERR("Failed to remove of %s", path.c_str());
+ }
+ }
+ };
+
+ scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
}
void install_Clean()
}
tacPluginFinished = true;
- if (tac_db) {
- dbClose(tac_db);
- tac_db = NULL;
- }
if (!strcmp("install", status.c_str())) {
install_Clean();
} else if (!strcmp("update", status.c_str())) {
} else if (!strcmp("uninstall", status.c_str())) {
unInstall_Clean();
}
+
+ if (tac_db) {
+ dbClose(tac_db);
+ tac_db = NULL;
+ }
+
+ if (tlc_db) {
+ dbClose(tlc_db);
+ tlc_db = NULL;
+ }
+
return 0;
}
_ERR("Failed to recursive directory: %s", error.what());
return;
}
+
+ ///// TLC /////
+ auto convert = [](const std::string& path, const std::string& filename) {
+ if (filename.rfind(".bck") != std::string::npos) {
+ if (!moveFile(path, replaceAll(path, ".bck", ""))) {
+ _ERR("Failed to move %s", path.c_str());
+ }
+ }
+ };
+
+ scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
}
void install_Undo()
_ERR("Failed to remove of %s", cd.c_str());
}
}
+
+ for (auto& cl : createLibraries) {
+ if (!removeFile(cl)) {
+ _ERR("Failed to remove of %s", cl.c_str());
+ }
+ }
}
void unInstall_Undo()
}
tacPluginFinished = true;
- if (tac_db) {
- dbRollback(tac_db);
- tac_db = NULL;
- }
if (!strcmp("install", status.c_str())) {
install_Undo();
} else if (!strcmp("update", status.c_str())) {
} else if (!strcmp("uninstall", status.c_str())) {
unInstall_Undo();
}
+
+ if (tac_db) {
+ dbRollback(tac_db);
+ tac_db = NULL;
+ }
+
+ if (tlc_db) {
+ dbRollback(tlc_db);
+ tlc_db = NULL;
+ }
+
return 0;
-}
+}
\ No newline at end of file
*/
#include <fstream>
+#include <regex>
#include <json/json.h>
#include <pkgmgr-info.h>
#include <pkgmgr_installer_info.h>
#include "utils.h"
#include "tac_common.h"
#include "db_manager.h"
-#include "path_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
#undef __XSTR
static sqlite3 *tac_db = NULL;
+static sqlite3 *tlc_db = NULL;
std::vector<std::string> restore_nuget;
+std::vector<std::string> restore_library;
static void cleanupDirectory()
{
bool isExist = false;
std::string nugetPath = nuget.path().string();
for (auto& restore : restore_nuget) {
- if (!bf::is_directory(nugetPath)) {
+ if (!bf::is_directory(nugetPath) || nugetPath.find(TLC_LIBRARIES_DIR) != std::string::npos) {
isExist = true;
+ break;
}
if (!strcmp(nugetPath.c_str(), restore.c_str()) ||
!strcmp(nugetPath.c_str(), restore.substr(0, restore.rfind('/')).c_str())) {
}
// callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
-static int restoreDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
+static int restoreTACDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
{
char *pkgId = NULL;
char *root = NULL;
fprintf(stderr, "Failed to get root path\n");
return -1;
}
- rootPath = root;
+ rootPath = std::string(root);
ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
if (ret != PMINFO_R_OK) {
return TAC_ERROR_UNKNOWN;
}
- ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, restoreDBCb, NULL);
+ ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, restoreTACDBCb, NULL);
if (ret != PMINFO_R_OK) {
fprintf(stderr, "Failed pkgmgrinfo_appinfo_metadata_filter_foreach\n");
pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
}
return parserData;
}
+
+std::vector<std::string> getLibrariesInfo(const std::string& rootPath)
+{
+ std::vector<std::string> LibrariesInfo;
+ std::vector<std::string> unusedDir;
+ std::string runtimesDir = concatPath(rootPath, "bin/runtimes");
+ if (!bf::exists(runtimesDir))
+ return LibrariesInfo;
+
+ char buffer[128];
+ sprintf(buffer, "(tizen|linux|unix|base|any)(.\\d.\\d.\\d)?(-%s)?", ARCHITECTURE_IDENTIFIER);
+ std::regex pattern(buffer);
+
+ try {
+ for (auto& path : bf::recursive_directory_iterator(runtimesDir)) {
+ std::string filepath = path.path().string();
+ std::size_t pos = filepath.rfind("/runtimes/");
+ if (pos != std::string::npos) {
+ std::string targetDir = filepath.substr(pos + 10);
+ if (!std::regex_match(targetDir.substr(0, targetDir.find('/')), pattern)) {
+ if (isDirectory(filepath))
+ unusedDir.push_back(filepath);
+ continue;
+ }
+ }
+ if (filepath.rfind(".so") == std::string::npos)
+ continue;
+
+ std::string buffer = SHA256(filepath);
+ LibrariesInfo.push_back(filepath + ":" + buffer);
+ _INFO("Library : [%s] / SHA256 : [%s]", filepath.substr(filepath.rfind('/') + 1).c_str(), buffer.c_str());
+ }
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ }
+
+ for (auto& path : unusedDir) {
+ if (!removeAll(path)) {
+ _ERR("Failed to remove of %s", path.c_str());
+ }
+ }
+ unusedDir.clear();
+
+ return LibrariesInfo;
+}
+
+// callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
+static int restoreTLCDBCb(pkgmgrinfo_appinfo_h handle, void *userData)
+{
+ char *pkgId = NULL;
+ char *root = NULL;
+ std::string rootPath;
+
+ int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
+ if (ret != PMINFO_R_OK) {
+ fprintf(stderr, "Failed to get pkgid\n");
+ return -1;
+ }
+
+ ret = pkgmgrinfo_appinfo_get_root_path(handle, &root);
+ if (ret != PMINFO_R_OK) {
+ fprintf(stderr, "Failed to get root path\n");
+ return -1;
+ }
+ rootPath = std::string(root);
+
+ for (auto& librarySha : getLibrariesInfo(rootPath)) {
+ std::string library = librarySha.substr(0, librarySha.find(':'));
+ if (bf::exists(library)) {
+ std::string fileSha = library.substr(library.rfind('/') + 1) + ".." + librarySha.substr(librarySha.find(':') + 1);
+ char *sql = sqlite3_mprintf("INSERT INTO TLC (PKGID, LIBRARY) VALUES (%Q, %Q);", pkgId, fileSha.c_str());
+ dbInsert(tlc_db, TLC_APP_LIST_RESTORE_DB, sql);
+ restore_library.push_back(fileSha);
+ sqlite3_free(sql);
+ }
+ }
+ return 0;
+}
+
+tac_error_e restoreTLCDB()
+{
+ if (!removeFile(TLC_APP_LIST_RESTORE_DB)) {
+ fprintf(stderr, "Failed to remove of %s\n", TLC_APP_LIST_RESTORE_DB);
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ std::string dbRestoreJournal = TLC_APP_LIST_RESTORE_DB + std::string("-journal");
+ if (!removeFile(dbRestoreJournal)) {
+ fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ tlc_db = dbCreate(TLC_APP_LIST_RESTORE_DB, CREATE_TLC_DB_TABLE);
+ if (!tlc_db) {
+ fprintf(stderr, "Sqlite create error\n");
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ pkgmgrinfo_appinfo_metadata_filter_h handle;
+ int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
+ if (ret != PMINFO_R_OK) {
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+ return TAC_ERROR_UNKNOWN;
+ }
+
+ ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, restoreTLCDBCb, NULL);
+ if (ret != PMINFO_R_OK) {
+ fprintf(stderr, "Failed pkgmgrinfo_appinfo_metadata_filter_foreach\n");
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+ return TAC_ERROR_UNKNOWN;
+ }
+ fprintf(stdout, "Success pkgmgrinfo_appinfo_metadata_filter_foreach\n");
+
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+
+ if (tlc_db) {
+ dbClose(tlc_db);
+ tlc_db = NULL;
+ }
+
+ const uid_t g_uid = 301; // app_fw
+ const gid_t g_gid = 301; // app_fw
+
+ if (!copyFile(TLC_APP_LIST_RESTORE_DB, TLC_APP_LIST_DB)) {
+ fprintf(stderr, "Failed to copy of %s\n", TLC_APP_LIST_DB);
+ return TAC_ERROR_UNKNOWN;
+ }
+ if (!removeFile(TLC_APP_LIST_RESTORE_DB)) {
+ fprintf(stderr, "Failed to remove of %s\n", TLC_APP_LIST_RESTORE_DB);
+ return TAC_ERROR_UNKNOWN;
+ }
+ if (chown(TLC_APP_LIST_DB, g_uid, g_gid) == -1) {
+ fprintf(stderr, "Failed to change owner and group name\n");
+ }
+
+ std::string dbJournal = TLC_APP_LIST_DB + std::string("-journal");
+ if (!copyFile(dbRestoreJournal, dbJournal)) {
+ fprintf(stderr, "Failed to copy of %s\n", dbJournal.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+ if (!removeFile(dbRestoreJournal)) {
+ fprintf(stderr, "Failed to remove of %s\n", dbRestoreJournal.c_str());
+ return TAC_ERROR_UNKNOWN;
+ }
+ if (chown(dbJournal.c_str(), g_uid, g_gid) == -1) {
+ fprintf(stderr, "Failed to change owner and group name\n");
+ }
+
+ auto convert = [](const std::string& path, const std::string& filename) {
+ bool isExist = false;
+ for (auto& library : restore_library) {
+ if (!strcmp(filename.c_str(), library.c_str())) {
+ isExist = true;
+ break;
+ }
+ }
+ if (!isExist) {
+ if (!removeFile(path)) {
+ _ERR("Failed to remove of %s", path.c_str());
+ }
+ }
+ };
+
+ scanFilesInDirectory(concatPath(__DOTNET_DIR, TLC_LIBRARIES_DIR), convert, 0);
+
+ return TAC_ERROR_NONE;
+}