#include <dirent.h>
#include <libgen.h>
-#include <sqlite3.h>
-
#include <tzplatform_config.h>
-#include <db-util.h>
#include "pkgmgr-info.h"
#include "pkgmgrinfo_debug.h"
#include "pkgmgrinfo_private.h"
#include "pkgmgr_parser.h"
#include "pkgmgr_parser_db.h"
+#include "manager/pkginfo_manager.h"
-typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
+typedef int (*sqlite_query_callback)(void *data, int ncols,
+ char **coltxt, char **colname);
-static int _mkdir_for_user(const char* dir, uid_t uid, gid_t gid)
+static int _mkdir_for_user(const char *dir, uid_t uid, gid_t gid)
{
int ret;
char *fullpath;
}
ret = fchown(fd, uid, gid);
if (ret == -1) {
- _LOGE("FAIL : fchown %s %d.%d, because %s", dir, uid,
- gid, strerror_r(errno, buf, sizeof(buf)));
+ _LOGE("FAIL : fchown %s %d.%d, because %s",
+ dir, uid, gid,
+ strerror_r(errno, buf, sizeof(buf)));
close(fd);
free(fullpath);
return -1;
return strdup(path);
}
-int _check_create_cert_db(void)
-{
- return pkgmgr_parser_initialize_cert_db();
-}
-
static gid_t _get_gid(const char *name)
{
char buf[BUFSIZE];
tzplatform_reset_user();
}
/* just allow certain users to create the dbspace directory if needed. */
- if (uid_caller == ROOT_UID || uid_caller == APPFW_UID ||
- uid_caller == uid)
+ if (uid_caller == ROOT_UID || uid_caller == APPFW_UID)
_mkdir_for_user(db_path, uid, gid);
}
free(db_path);
API char *getUserPkgCertDBPath(void)
{
- return getUserPkgCertDBPathUID(_getuid());
-}
-
-API char *getUserPkgCertDBPathUID(uid_t uid)
-{
- char pkgmgr_cert_db[PATH_MAX];
- uid_t uid_caller = getuid();
- gid_t gid = ROOT_UID;
char *db_path;
+ char pkgmgr_cert_db[PATH_MAX];
- db_path = _get_db_path(uid);
- if (db_path == NULL) {
- _LOGE("Failed to get db path %d", uid);
- return NULL;
- }
+ db_path = _get_db_path(GLOBAL_USER);
snprintf(pkgmgr_cert_db, sizeof(pkgmgr_cert_db),
"%s/.pkgmgr_cert.db", db_path);
-
- if (uid != GLOBAL_USER && uid != ROOT_UID) {
- tzplatform_set_user(uid);
- gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
- tzplatform_reset_user();
- }
-
- /* just allow certain users to create the dbspace directory if needed. */
- if (uid_caller == ROOT_UID || uid_caller == APPFW_UID || uid_caller == uid)
- _mkdir_for_user(db_path, uid, gid);
-
free(db_path);
return strdup(pkgmgr_cert_db);
}
/* just allow certain users to create the icon directory if needed. */
- if (uid_caller == ROOT_UID || uid_caller == APPFW_UID || uid_caller == uid)
+ if (uid_caller == ROOT_UID || uid_caller == APPFW_UID ||
+ uid_caller == uid)
_mkdir_for_user(path, uid, gid);
return path;
}
-void _save_column_int(sqlite3_stmt *stmt, int idx, int *i)
-{
- *i = sqlite3_column_int(stmt, idx);
-}
-
-inline void _save_column_str(sqlite3_stmt *stmt, int idx, char **str)
-{
- const char *val;
-
- val = (const char *)sqlite3_column_text(stmt, idx);
- if (val)
- *str = strdup(val);
-}
-
-API int pkgmgrinfo_pkginfo_set_usr_installed_storage(const char *pkgid, INSTALL_LOCATION location, const char *external_pkg_path, 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;
- sqlite3 *pkgmgr_parser_db = NULL;
- char *query = NULL;
- char *db_path;
- const char *location_str;
-
- db_path = getUserPkgParserDBPathUID(uid);
- if (db_path == NULL) {
- _LOGE("Failed to get pkg parser db path - %d", uid);
- return PMINFO_R_ERROR;
- }
-
- ret = db_util_open_with_options(db_path, &pkgmgr_parser_db,
- SQLITE_OPEN_READWRITE, NULL);
- if (ret != SQLITE_OK) {
- _LOGE("connect db failed!");
- free(db_path);
- return PMINFO_R_ERROR;
- }
- free(db_path);
-
- /*Begin transaction*/
- /* Setting Manifest DB */
- ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
- tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Failed to begin transaction\n");
- _LOGD("Transaction Begin\n");
-
- if (location == INSTALL_INTERNAL)
- location_str = "installed_internal";
- else if (location == INSTALL_EXTERNAL)
- location_str = "installed_external";
- else
- location_str = "installed_extended";
- /* pkgcakge_info table */
- query = sqlite3_mprintf(
- "update package_info set installed_storage=%Q, external_path=%Q where package=%Q",
- location_str, 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);
- sqlite3_free(query);
-
- /* package_app_info table */
- query = sqlite3_mprintf(
- "update package_app_info set app_installed_storage=%Q, app_external_path=%Q where package=%Q",
- location_str, 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);
-
- /*Commit transaction*/
- ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- _LOGE("Failed to commit transaction. Rollback now\n");
- ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
- tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
- }
- _LOGD("Transaction Commit and End\n");
-
- ret = PMINFO_R_OK;
-catch:
- sqlite3_close(pkgmgr_parser_db);
- sqlite3_free(query);
- return ret;
+ return _pkginfo_set_usr_installed_storage(pkgid,
+ location, external_pkg_path, uid);
}
-API int pkgmgrinfo_pkginfo_set_installed_storage(const char *pkgid, INSTALL_LOCATION location, const char *external_pkg_path)
+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, external_pkg_path, _getuid());
+ return pkgmgrinfo_pkginfo_set_usr_installed_storage(pkgid,
+ location, external_pkg_path, _getuid());
}