Fix UpdateCache related with storage check 14/277314/5
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 5 Jul 2022 04:53:34 +0000 (13:53 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 7 Jul 2022 02:33:45 +0000 (11:33 +0900)
If there is not check_storage value in the filter
storage check logic is performed by default
when the external_path of the package installed in the external is not accessible
the package's information is not inclued in the cache
This logic must be performed when the client requests package information

Change-Id: Iaaee5231fa939c1c8a7af3ca6f6049674832e965
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/pkgmgrinfo_private.h
src/server/appinfo_internal.cc
src/server/database/db_handle_provider.cc
src/server/filter_checker/app_filter_checker/check_storage_app_filter_checker.cc
src/server/pkginfo_internal.c
src/server/pkgmgrinfo_internal.h
src/server/pkgmgrinfo_internal.hh

index e774708..b79b6ef 100644 (file)
@@ -206,6 +206,7 @@ typedef struct _pkgmgrinfo_filter_x {
        uid_t uid;
        GSList *list;
        GSList *list_metadata;
+       bool cache_flag;        /* flag for pkginfo-server used to make cache */
 } pkgmgrinfo_filter_x;
 
 typedef struct _pkgmgrinfo_node_x {
index ad790a4..c8ce2ef 100644 (file)
@@ -387,7 +387,7 @@ int _get_filtered_query(pkgmgrinfo_filter_x* filter, const char* locale,
   if (!filter)
     return PMINFO_R_OK;
 
-  if (g_slist_length(filter->list) == 0) {
+  if (filter->cache_flag) {
     joined = E_PMINFO_APPINFO_JOIN_LOCALIZED_INFO |
       E_PMINFO_APPINFO_JOIN_CATEGORY |
       E_PMINFO_APPINFO_JOIN_APP_CONTROL |
@@ -461,6 +461,9 @@ bool __check_app_storage_status(pkgmgrinfo_filter_x* tmp_filter) {
   if (tmp_filter == nullptr)
     return true;
 
+  if (tmp_filter->cache_flag)
+    return false;
+
   property = _pminfo_appinfo_convert_to_prop_bool(
       PMINFO_APPINFO_PROP_APP_CHECK_STORAGE);
   for (tmp_list = tmp_filter->list; tmp_list != nullptr;
@@ -778,6 +781,10 @@ __catch:
 namespace pkgmgr_server {
 namespace internal {
 
+API bool check_app_storage_status(pkgmgrinfo_filter_x* tmp_filter) {
+  return ::__check_app_storage_status(tmp_filter);
+}
+
 API int appinfo_internal_filter_get_list(sqlite3* db,
     pkgmgrinfo_appinfo_filter_h filter, uid_t db_uid, uid_t uid,
     const char* locale,
index 14c3f30..6720378 100644 (file)
@@ -355,6 +355,7 @@ int DBHandleProvider::UpdateCache(sqlite3* db, pid_t pid, uid_t uid, bool write,
   }
 
   pkgmgrinfo_filter_x tmp_filter = { 0, };
+  tmp_filter.cache_flag = true;
   int ret = pkginfo_internal_filter_get_list(db, &tmp_filter, uid_,
                                              locale.c_str(), list);
   if (ret == PMINFO_R_OK) {
@@ -420,6 +421,14 @@ std::vector<std::shared_ptr<package_x>> DBHandleProvider::GetPackages(
   if (map_it == pkg_map_.end())
     return ret;
 
+  if (__check_package_storage_status(filter)) {
+    if (pkgmgrinfo_pkginfo_filter_add_bool(filter,
+        PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE, true) != PMINFO_R_OK) {
+      LOG(ERROR) << "Fail to add check storage value to filter";
+      return {};
+    }
+  }
+
   for (auto& info : map_it->second) {
     bool pass = true;
     for (auto* it = filter->list; it != nullptr; it = g_slist_next(it)) {
@@ -462,6 +471,14 @@ std::vector<std::shared_ptr<application_x>> DBHandleProvider::GetApplications(
   if (map_it == app_map_.end())
     return ret;
 
+  if (pkgmgr_server::internal::check_app_storage_status(filter)) {
+    if (pkgmgrinfo_appinfo_filter_add_bool(filter,
+        PMINFO_APPINFO_PROP_APP_CHECK_STORAGE, true) != PMINFO_R_OK) {
+      LOG(ERROR) << "Fail to add check storage value to filter";
+      return {};
+    }
+  }
+
   for (auto& info : map_it->second) {
     bool pass = true;
     for (auto* it = filter->list; it != nullptr; it = g_slist_next(it)) {
index b14eaa6..8878aab 100644 (file)
@@ -20,8 +20,9 @@ namespace pkgmgr_server {
 namespace database {
 
 bool CheckStorageAppFilterChecker::CheckFilter(pkgmgrinfo_node_x* node,
-                                             application_x* info) {
-  return true;
+    application_x* info) {
+  return (node->value == nullptr || strcasecmp(node->value, "true") != 0 ||
+      __appinfo_check_installed_storage(info) == PMINFO_R_OK);
 }
 
 }  // namespace database
index 41d3bda..3873f4c 100644 (file)
@@ -80,7 +80,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        if (!filter)
                return PMINFO_R_OK;
 
-       if (g_slist_length(filter->list) == 0) {
+       if (filter->cache_flag) {
                joined = E_PMINFO_PKGINFO_JOIN_LOCALIZED_INFO |
                        E_PMINFO_PKGINFO_JOIN_PRIVILEGE_INFO |
                        E_PMINFO_PKGINFO_JOIN_RES_INFO;
@@ -142,12 +142,15 @@ static int __bind_params(sqlite3_stmt *stmt, GList *params)
        return PMINFO_R_OK;
 }
 
-static bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
+bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter)
 {
        GSList *tmp_list = NULL;
        pkgmgrinfo_node_x *tmp_node = NULL;
        int property = -1;
 
+       if (tmp_filter->cache_flag)
+               return false;
+
        property = _pminfo_pkginfo_convert_to_prop_bool(
                                PMINFO_PKGINFO_PROP_PACKAGE_CHECK_STORAGE);
        for (tmp_list = tmp_filter->list; tmp_list != NULL;
index 7038cbc..cef3d7c 100644 (file)
@@ -25,6 +25,7 @@
 #include <sqlite3.h>
 
 #include "pkgmgr_parser.h"
+#include "pkgmgrinfo_private.h"
 #include "pkgmgrinfo_type.h"
 #include "pkgmgr-info.h"
 #ifdef __cplusplus
@@ -95,6 +96,7 @@ int get_query_result(sqlite3 *db, const char *query, GList *param, GList **list,
 int execute_write_queries(sqlite3 *db, GList *queries, GList *params_list);
 int pkginfo_internal_filter_get_depends_on(sqlite3 *db, const char *pkgid, GList **list);
 
+bool __check_package_storage_status(pkgmgrinfo_filter_x *tmp_filter);
 void _save_column_int(sqlite3_stmt *stmt, int idx, int *i);
 void _save_column_str(sqlite3_stmt *stmt, int idx, char **str);
 
index c3cfdd2..a51502f 100644 (file)
@@ -31,6 +31,8 @@
 namespace pkgmgr_server {
 namespace internal {
 
+extern API bool check_app_storage_status(pkgmgrinfo_filter_x* tmp_filter);
+
 extern API int appinfo_internal_filter_get_list(sqlite3* db,
     pkgmgrinfo_appinfo_filter_h filter, uid_t db_uid, uid_t uid,
     const char* locale,