Change permission of pkgmgr db files
[platform/core/appfw/pkgmgr-info.git] / parser / src / pkgmgr_parser_db.c
index a7fbaa9..d5c516c 100644 (file)
@@ -50,6 +50,7 @@
 #define MAX_QUERY_LEN          4096
 #define BUFSIZE 4096
 #define OWNER_ROOT 0
+#define APPFW_USER "app_fw"
 #define MAX_INTEGER_LENGTH 10
 
 #define LDPI "ldpi"
@@ -544,7 +545,7 @@ static int __exec_query(char *query)
        }
        sqlite3_free(error_message);
 
-       if (sqlite3_changes(pkgmgr_parser_db) == 0) {
+       if (strncmp(query, "DELETE", 6) && sqlite3_changes(pkgmgr_parser_db) == 0) {
                _LOGE("No such record matches with given query : %s\n", query);
                return -1;
        }
@@ -2411,8 +2412,13 @@ static int __parserdb_change_perm(const char *db_file, uid_t uid)
        if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
                return 0;
        snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
-       if (uid == OWNER_ROOT)
-               uid = GLOBAL_USER;
+       if (uid == OWNER_ROOT || uid == GLOBAL_USER) {
+               ret = getpwnam_r(APPFW_USER, &userinfo, buf, sizeof(buf), &result);
+               if (ret != 0 || result == NULL)
+                       return -1;
+               uid = userinfo.pw_uid;
+       }
+
        ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
        if (ret != 0 || result == NULL) {
                _LOGE("FAIL: user %d doesn't exist", uid);