Add external_path column and change function related with it 72/91972/6 submit/tizen/20161102.115555
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 12 Oct 2016 10:49:41 +0000 (19:49 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 1 Nov 2016 07:19:03 +0000 (16:19 +0900)
- Add external_path column at package_info table
to store loopback device path when pkg has moved into
external storage

Change-Id: I31b9402bbcf96c5ff45b89640561aa5e7c22505a
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
include/pkgmgr-info.h
include/pkgmgrinfo_basic.h
include/pkgmgrinfo_private.h
parser/pkgmgr_parser_db.c
src/pkgmgrinfo_appinfo.c
src/pkgmgrinfo_basic.c
src/pkgmgrinfo_db.c
src/pkgmgrinfo_pkginfo.c
src/pkgmgrinfo_private.c

index 8ab3f7c..a49b209 100644 (file)
@@ -5450,6 +5450,7 @@ int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool
 *
 * @param[in] pkgid             pointer to the package ID.
 * @param[in] location  package install location
+* @param[in] external_pkg_path  image path if pkg has installed at external storage
 * @return  0 if success, error code(<0) if fail
 * @retval  PMINFO_R_OK success
 * @retval  PMINFO_R_EINVAL      invalid argument
@@ -5467,8 +5468,8 @@ static int set_app_installed_storage(const char *appid, INSTALL_LOCATION locatio
 }
 * @endcode
 */
-int pkgmgrinfo_pkginfo_set_installed_storage(const char *pkgid, INSTALL_LOCATION location);
-int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char * pkgid, INSTALL_LOCATION location, uid_t uid);
+int pkgmgrinfo_pkginfo_set_installed_storage(const char *pkgid, INSTALL_LOCATION location, const char *external_pkg_path);
+int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char * pkgid, INSTALL_LOCATION location, const char *external_pkg_path, uid_t uid);
 
 /**
  * @brief      TEMP
index 9df5ab3..65988cf 100644 (file)
@@ -151,6 +151,7 @@ typedef struct application_x {
        char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only, no xml part*/
        char *is_disabled; /**< Flag that indicates if the application is disabled or not, no xml part*/
        char *splash_screen_display; /*attr, default: "true"*/
+       char *external_path; /**< external storage path if exists, no xml part*/
        GList *label;   /*element*/
        GList *icon;    /*element*/
        GList *image;   /*element*/
@@ -194,6 +195,7 @@ typedef struct package_x {
        char *tep_name; /*no xml part*/
        char *zip_mount_file;   /*no xml part*/
        char *backend_installer;                /**< package backend installer, attr*/
+       char *external_path; /**< external storage path if exists, no xml part*/
        GList *icon;            /**< package icon, element*/
        GList *label;           /**< package label, element*/
        GList *author;          /**< package author, element*/
index d72c01d..ab1189d 100644 (file)
@@ -240,6 +240,8 @@ char *_get_system_locale(void);
 int __get_filter_condition(gpointer data, char **condition, GList **param);
 int _add_icon_info_into_list(const char *locale, char *value, GList **icon);
 int _add_label_info_into_list(const char *locale, char *value, GList **label);
+int __pkginfo_check_installed_storage(package_x *pkginfo);
+int __appinfo_check_installed_storage(application_x *appinfo);
 
 #define REGULAR_USER 5000
 static inline uid_t _getuid(void)
index c403315..494f231 100644 (file)
@@ -111,6 +111,7 @@ sqlite3 *pkgmgr_cert_db;
                                                "mainapp_id TEXT, " \
                                                "package_url TEXT, " \
                                                "root_path TEXT, " \
+                                               "external_path TEXT, " \
                                                "csc_path TEXT, " \
                                                "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
                                                "package_disable TEXT NOT NULL DEFAULT 'false')"
@@ -176,6 +177,7 @@ sqlite3 *pkgmgr_cert_db;
                                                "app_api_version TEXT, " \
                                                "app_effective_appid TEXT, " \
                                                "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
+                                               "app_external_path TEXT, " \
                                                "FOREIGN KEY(package) " \
                                                "REFERENCES package_info(package) " \
                                                "ON DELETE CASCADE)"
index b6d22b2..e16d0ef 100644 (file)
@@ -463,7 +463,8 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                "ai.app_package_type, ai.app_root_path, ai.app_api_version, "
                "ai.app_effective_appid, ai.app_disable, "
                "ai.app_splash_screen_display, ai.app_tep_name, "
-               "ai.app_zip_mount_file, ai.component_type, ai.package";
+               "ai.app_zip_mount_file, ai.component_type, ai.package, "
+               "ai.app_external_path";
        static const char query_label[] =
                ", COALESCE("
                "(SELECT app_label FROM package_app_localized_info WHERE ai.app_id=app_id AND app_locale=?), "
@@ -590,6 +591,7 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                _save_column_str(stmt, idx++, &info->zip_mount_file);
                _save_column_str(stmt, idx++, &info->component_type);
                _save_column_str(stmt, idx++, &info->package);
+               _save_column_str(stmt, idx++, &info->external_path);
                info->for_all_users =
                        strdup((uid != GLOBAL_USER) ? "false" : "true");
 
@@ -659,6 +661,13 @@ static int _appinfo_get_applications(uid_t db_uid, uid_t uid,
                        }
                }
 
+               if (__appinfo_check_installed_storage(info) != PMINFO_R_OK) {
+                       ret = PMINFO_R_ERROR;
+                       pkgmgrinfo_basic_free_application(info);
+                       info = NULL;
+                       continue;
+               }
+
                g_hash_table_insert(applications, (gpointer)info->appid,
                                (gpointer)info);
        }
index 060f264..2399af2 100644 (file)
@@ -328,6 +328,8 @@ static void __ps_free_application(gpointer data)
                free((void *)application->ambient_support);
        if (application->alias_appid)
                free((void *)application->alias_appid);
+       if (application->external_path)
+               free((void *)application->external_path);
 
        /*Free Label*/
        g_list_free_full(application->label, __ps_free_label);
@@ -420,6 +422,8 @@ API void pkgmgrinfo_basic_free_package(package_x *package)
                free((void *)package->tep_name);
        if (package->zip_mount_file)
                free((void *)package->zip_mount_file);
+       if (package->external_path)
+               free((void *)package->external_path);
 
        /*Free Icon*/
        g_list_free_full(package->icon, __ps_free_icon);
index 7f8ecf8..c16f7d3 100644 (file)
@@ -538,7 +538,7 @@ void _save_column_str(sqlite3_stmt *stmt, int idx, char **str)
                *str = strdup(val);
 }
 
-API int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_LOCATION location, uid_t uid)
+API int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_LOCATION location, const char *external_pkg_path, uid_t uid)
 {
        retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
        int ret = -1;
@@ -569,8 +569,8 @@ API int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_
 
        /* pkgcakge_info table */
        query = sqlite3_mprintf(
-                       "update package_info set installed_storage=%Q where package=%Q",
-                       location ? "installed_external" : "installed_internal", pkgid);
+                       "update package_info set installed_storage=%Q, external_path=%Q where package=%Q",
+                       location ? "installed_external" : "installed_internal", external_pkg_path, pkgid);
 
        ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, NULL);
        tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
@@ -578,8 +578,8 @@ API int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_
 
        /* package_app_info table */
        query = sqlite3_mprintf(
-                       "update package_app_info set app_installed_storage=%Q where package=%Q",
-                       location ? "installed_external" : "installed_internal", pkgid);
+                       "update package_app_info set app_installed_storage=%Q, app_external_path=%Q where package=%Q",
+                       location ? "installed_external" : "installed_internal", external_pkg_path, pkgid);
 
        ret = sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, NULL);
        tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
@@ -600,7 +600,7 @@ catch:
        return ret;
 }
 
-API int pkgmgrinfo_pkginfo_set_installed_storage(const char *pkgid, INSTALL_LOCATION location)
+API int pkgmgrinfo_pkginfo_set_installed_storage(const char *pkgid, INSTALL_LOCATION location, const char *external_pkg_path)
 {
-       return pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid, location, _getuid());
+       return pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid, location, external_pkg_path, _getuid());
 }
index be7f4e7..ea10d24 100644 (file)
@@ -297,7 +297,7 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                "pi.storeclient_id, pi.mainapp_id, pi.package_url, "
                "pi.root_path, pi.csc_path, pi.package_nodisplay, "
                "pi.package_api_version, pi.package_support_disable, "
-               "pi.package_tep_name, pi.package_zip_mount_file";
+               "pi.package_tep_name, pi.package_zip_mount_file, pi.external_path";
        static const char query_author[] =
                ", pi.author_name, pi.author_email, pi.author_href";
        static const char query_label[] =
@@ -437,6 +437,7 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                _save_column_str(stmt, idx++, &info->support_disable);
                _save_column_str(stmt, idx++, &info->tep_name);
                _save_column_str(stmt, idx++, &info->zip_mount_file);
+               _save_column_str(stmt, idx++, &info->external_path);
                info->for_all_users =
                        strdup((uid != GLOBAL_USER) ? "false" : "true");
 
@@ -500,6 +501,13 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
                        }
                }
 
+               if (__pkginfo_check_installed_storage(info) != PMINFO_R_OK) {
+                       ret = PMINFO_R_ERROR;
+                       pkgmgrinfo_basic_free_package(info);
+                       info = NULL;
+                       continue;
+               }
+
                g_hash_table_insert(packages, (gpointer)info->package,
                                (gpointer)info);
        }
index d740f30..3c3c23a 100644 (file)
@@ -469,3 +469,38 @@ char *_get_system_locale(void)
        return locale;
 }
 
+int __pkginfo_check_installed_storage(package_x *pkginfo)
+{
+       char buf[MAX_QUERY_LEN] = {'\0'};
+       retvm_if(pkginfo->package == NULL, PMINFO_R_OK, "pkgid is NULL\n");
+       retvm_if(pkginfo->installed_storage == NULL, PMINFO_R_ERROR,
+                       "installed_storage is NULL\n");
+
+       if (strcmp(pkginfo->installed_storage, "installed_external") == 0) {
+               snprintf(buf, MAX_QUERY_LEN - 1, "%s", pkginfo->external_path);
+               if (access(buf, R_OK) != 0) {
+                       _LOGE("can not access [%s]", buf);
+                       return PMINFO_R_ERROR;
+               }
+       }
+
+       return PMINFO_R_OK;
+}
+
+int __appinfo_check_installed_storage(application_x *appinfo)
+{
+       retvm_if(appinfo->installed_storage == NULL, PMINFO_R_ERROR,
+                       "installed_storage is NULL\n");
+
+       if (strcmp(appinfo->installed_storage, "installed_external") == 0) {
+               retvm_if(appinfo->external_path == NULL, PMINFO_R_ERROR,
+                               "external path is NULL\n");
+               if (access(appinfo->external_path, R_OK) != 0) {
+                       _LOGE("can not access [%s]", appinfo->external_path);
+                       return PMINFO_R_ERROR;
+               }
+       }
+
+       return PMINFO_R_OK;
+}
+