Use pkgmgr API to get the parser db path 51/81451/5
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 26 Jul 2016 08:59:45 +0000 (17:59 +0900)
committerSemun Lee <sm79.lee@samsung.com>
Mon, 8 Aug 2016 04:19:52 +0000 (21:19 -0700)
- Requires
https://review.tizen.org/gerrit/81322

Change-Id: I0430ef10a23bb0448990d67561077292021b29d4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/service_db.c

index 4e6edea..6f9eb01 100755 (executable)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <tzplatform_config.h>
+#include <pkgmgr-info.h>
 
 #include "aul_svc_db.h"
 #include "aul_util.h"
@@ -146,36 +147,6 @@ static const char *__get_svc_db(uid_t uid)
        return appsvc_db;
 }
 
-
-static const char *__get_app_info_db(uid_t uid)
-{
-       const char *app_info_db = NULL;
-       const char *db_path = NULL;
-       uid_t uid_caller = getuid();
-       gid_t gid = ROOT_UID;
-
-       if (uid == ROOT_UID) {
-               _E("Fail to get appsvc db. root is not allowed");
-               return NULL;
-       }
-
-       if (uid != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) {
-               tzplatform_set_user(uid);
-               app_info_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db");
-               db_path = tzplatform_getenv(TZ_USER_DB);
-               gid = tzplatform_getgid(TZ_USER_NAME);
-               tzplatform_reset_user();
-       } else {
-               app_info_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
-               db_path = tzplatform_getenv(TZ_SYS_DB);
-       }
-
-       if (uid_caller == ROOT_UID || uid_caller == uid)
-               __mkdir_for_user(db_path, uid, gid);
-
-       return app_info_db;
-}
-
 /**
  * db initialize
  */
@@ -284,13 +255,21 @@ static int __collate_appsvc(void *ucol, int str1_len, const void *str1,
 static int __init_app_info_db(uid_t uid)
 {
        int rc;
+       char *db_path;
 
        if (app_info_db) {
                _D("Already initialized\n");
                return 0;
        }
 
-       rc = sqlite3_open_v2(__get_app_info_db(uid), &app_info_db, SQLITE_OPEN_READONLY, NULL);
+       db_path = getUserPkgParserDBPathUID(uid);
+       if (db_path == NULL) {
+               _E("Failed to get pkg parser db path - %d", uid);
+               return -1;
+       }
+
+       rc = sqlite3_open_v2(db_path, &app_info_db, SQLITE_OPEN_READONLY, NULL);
+       free(db_path);
        if (rc) {
                _E("Can't open database: %d, %s, extended: %d", rc, sqlite3_errmsg(app_info_db),
                   sqlite3_extended_errcode(app_info_db));