Modify regenerate all tac file in dotnettool
authorj-h.choi <j-h.choi@samsung.com>
Fri, 11 Oct 2019 02:17:14 +0000 (11:17 +0900)
committer이형주/Common Platform Lab(SR)/Staff Engineer/삼성전자 <leee.lee@samsung.com>
Mon, 14 Oct 2019 21:55:21 +0000 (06:55 +0900)
NativeLauncher/tool/ni_common.cc

index d31e7d1..6df388c 100644 (file)
 #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"
@@ -454,37 +456,26 @@ ni_error_e createNiDll(const std::string& dllPath, DWORD flags)
        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);
        }
 }
 
@@ -691,8 +682,9 @@ void removeNiUnderDirs(const std::string rootPaths[], int count)
                }
        };
 
-       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)
@@ -753,10 +745,63 @@ ni_error_e regenerateAppNI(DWORD flags)
        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;
 }