#include <grp.h>
#include <unistd.h>
#include <string.h>
+#include <sqlite3.h>
#include "ni_common.h"
+#include "db_manager.h"
#include "tac_common.h"
#include "path_manager.h"
#include "plugin_manager.h"
return status;
}
-void createNiUnderTAC(const std::string rootPaths[], int count, DWORD flags)
+void createNiUnderTAC(std::vector<std::string> nugets, DWORD flags)
{
std::string appPaths;
- try {
- for (auto& nuget : bf::recursive_directory_iterator(__TAC_DIR)) {
- std::string nugetPath = nuget.path().string();
- if (bf::is_directory(nugetPath)) {
- appPaths += nugetPath;
- appPaths += ':';
- }
- }
- if (appPaths.back() == ':') {
- appPaths.pop_back();
- }
-
- auto convert = [&appPaths, flags](const std::string& path, const char* name) {
- if (strstr(path.c_str(), TAC_APP_LIST_DB) != NULL ||
- strstr(path.c_str(), TAC_APP_LIST_RESTORE_DB) != NULL ||
- strstr(path.c_str(), TAC_SHA_256_INFO) != NULL)
- return;
- if (!crossgen(path, appPaths.c_str(), flags)) {
- waitInterval();
- }
- };
+ for (auto& nuget : nugets) {
+ appPaths += concatPath(__TAC_DIR, nuget);
+ appPaths += ':';
+ }
+ if (appPaths.back() == ':') {
+ appPaths.pop_back();
+ }
- for (int i = 0; i < count; i++) {
- scanFilesInDir(rootPaths[i], convert, -1);
+ auto convert = [&appPaths, flags](const std::string& path, const char* name) {
+ if (strstr(path.c_str(), TAC_SHA_256_INFO) != NULL)
+ return;
+ if (!crossgen(path, appPaths.c_str(), flags)) {
+ waitInterval();
}
- } catch (const bf::filesystem_error& error) {
- fprintf(stderr, "Failed to recursive directory: %s\n", error.what());
- return;
+ };
+ for (auto& nuget : nugets) {
+ scanFilesInDir(concatPath(__TAC_DIR, nuget), convert, -1);
}
}
}
};
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++) {
scanFilesInDir(rootPaths[i], convert, -1);
+ }
}
ni_error_e removeNiUnderPkgRoot(const std::string& pkgId)
return NI_ERROR_NONE;
}
+// callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
+static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData)
+{
+ char *pkgId = NULL;
+ DWORD *pFlags = (DWORD*)userData;
+
+ int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
+ if (ret != PMINFO_R_OK) {
+ fprintf(stderr, "Failed to get pkgid\n");
+ return -1;
+ }
+
+ sqlite3 *tac_db = dbOpen(TAC_APP_LIST_DB);
+ if (!tac_db) {
+ fprintf(stderr, "Sqlite open error\n");
+ return -1;
+ }
+
+ std::string sql = "SELECT * FROM TAC WHERE PKGID = '" + std::string(pkgId) + "';";
+ std::vector<std::string> nugets = dbSelect(tac_db, TAC_APP_LIST_DB, sql);
+
+ if (tac_db) {
+ dbClose(tac_db);
+ tac_db = NULL;
+ }
+
+ createNiUnderTAC(nugets, *pFlags);
+
+ return 0;
+}
+
ni_error_e regenerateTACNI(DWORD flags)
{
const std::string tacDir[] = {__TAC_DIR};
removeNiUnderDirs(tacDir, 1);
- createNiUnderTAC(tacDir, 1, flags);
+
+ pkgmgrinfo_appinfo_metadata_filter_h handle;
+ int ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle);
+ if (ret != PMINFO_R_OK) {
+ return NI_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 NI_ERROR_UNKNOWN;
+ }
+
+ ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, regenTacCb, &flags);
+ if (ret != PMINFO_R_OK) {
+ fprintf(stderr, "Failed pkgmgrinfo_appinfo_metadata_filter_foreach\n");
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+ return NI_ERROR_UNKNOWN;
+ }
+ fprintf(stderr, "Success pkgmgrinfo_appinfo_metadata_filter_foreach\n");
+
+ pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
+
return NI_ERROR_NONE;
}