UID will be included with it.
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
ret = _appinfo_get_applications(db, uid, uid, locale, filter,
PMINFO_APPINFO_GET_ALL, appinfo_list);
- if (!g_hash_table_size(appinfo_list) && uid != GLOBAL_USER)
- ret = _appinfo_get_applications(db, GLOBAL_USER, uid, locale, filter,
- PMINFO_APPINFO_GET_ALL, appinfo_list);
return ret;
}
AbstractDBHandler::~AbstractDBHandler() {
// Is this necessary?
for (auto db_handle : db_handle_list_)
- sqlite3_close(db_handle);
+ sqlite3_close(db_handle.first);
}
-std::vector<std::string> AbstractDBHandler::GetDBPath() {
- std::vector<std::string> db_path;
+std::vector<std::pair<std::string, uid_t>> AbstractDBHandler::GetDBPath() {
+ std::vector<std::pair<std::string, uid_t>> db_path;
if (db_type_ == DB_TYPE_FILE_PKGDB) {
db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath(pid_);
} else if (db_type_ == DB_TYPE_FILE_CERTDB) {
- db_path.emplace_back(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_));
+ db_path.emplace_back(std::make_pair(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_), uid_));
}
return db_path;
int ret = 0;
sqlite3* db;
for (auto dbpath : dbpath_list) {
- if (op_type_ == OPERATION_TYPE_READ)
- ret = __open_read_db(dbpath.c_str(), &db, SQLITE_OPEN_READONLY |
+ if (op_type_ == OPERATION_TYPE_READ) {
+ ret = __open_read_db(dbpath.first.c_str(), &db, SQLITE_OPEN_READONLY |
SQLITE_OPEN_URI);
- else
- ret = __open_write_db(uid_, dbpath.c_str(), &db,
+ } else {
+ if (dbpath.second != uid_)
+ continue;
+ ret = __open_write_db(uid_, dbpath.first.c_str(), &db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
- // TODO: if write request has received, only one database should be delivered
+ }
+
if (ret != SQLITE_OK)
return false;
- db_handle_list_.emplace_back(db);
+ db_handle_list_.emplace_back(std::make_pair(db, dbpath.second));
}
return true;
*/
}
-std::vector<sqlite3*> AbstractDBHandler::GetConnection() {
+std::vector<std::pair<sqlite3*, uid_t>> AbstractDBHandler::GetConnection() {
return db_handle_list_;
}
protected:
bool Connect();
int GetPID();
- std::vector<sqlite3*> GetConnection();
+ std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
std::string GetLocale();
private:
- std::vector<std::string> GetDBPath();
+ std::vector<std::pair<std::string, uid_t>> GetDBPath();
DBType db_type_ = DB_TYPE_NONE;
OperationType op_type_ = OPERATION_TYPE_NONE;
uid_t uid_;
pid_t pid_;
std::string locale_;
- std::vector<sqlite3*> db_handle_list_;
+ std::vector<std::pair<sqlite3*, uid_t>> db_handle_list_;
};
} // namespace database
GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, __free_applications);
- std::vector<sqlite3*> conn_list = GetConnection();
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
int ret = PMINFO_R_OK;
for (auto conn : conn_list) {
- ret = appinfo_internal_filter_get_list(conn, filter_, uid_,
+ ret = appinfo_internal_filter_get_list(conn.first, filter_, conn.second,
GetLocale().c_str(), list);
if (ret == PMINFO_R_ERROR) {
_LOGE("Failed to appinfo_internal_filter_get_list (%d)", ret);
return ret;
handle_ = static_cast<pkgmgr_certinfo_x*>(handle);
- sqlite3* conn = GetConnection().front();
+ sqlite3* conn = GetConnection().front().first;
ret = certinfo_internal_get(conn, pkgid_.c_str(), uid_, handle_);
return ret;
return PMINFO_R_ERROR;
DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true);
- sqlite3 *conn = GetConnection().front();
+ sqlite3 *conn = GetConnection().front().first;
int ret = certinfo_internal_set(conn, handle_->pkgid, handle_, uid_);
return ret;
return *prov;
}
-std::vector<std::string> DBHandleProvider::GetParserDBPath(pid_t pid) {
+std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(pid_t pid) {
std::unique_lock<std::recursive_mutex> u(lock_);
std::unique_lock<std::recursive_mutex> gu(global_lock_);
- std::vector<std::string> db_path_list;
+ std::vector<std::pair<std::string, uid_t>> db_path_list;
if (is_memory_ != is_memory_global_)
SetMemoryMode(pid, is_memory_global_);
if (is_memory_ && pid_list_.find(pid) == pid_list_.end()) {
if (uid_ > REGULAR_USER)
- db_path_list.emplace_back(parser_memory_db_path_);
- db_path_list.emplace_back(global_parser_memory_db_path_);
+ db_path_list.emplace_back(std::make_pair(parser_memory_db_path_, uid_));
+ db_path_list.emplace_back(std::make_pair(global_parser_memory_db_path_, GetGlobalUID()));
} else {
if (uid_ > REGULAR_USER)
- db_path_list.emplace_back(parser_file_db_path_);
- db_path_list.emplace_back(global_parser_file_db_path_);
+ db_path_list.emplace_back(std::make_pair(parser_file_db_path_, uid_));
+ db_path_list.emplace_back(std::make_pair(global_parser_file_db_path_, GetGlobalUID()));
}
if (db_path_list.size() == 1) {
- LOGD("global db path : %s", db_path_list[0].c_str());
+ LOGD("global db path : %s", db_path_list[0].first.c_str());
} else {
- LOGD("local db path : %s", db_path_list[0].c_str());
- LOGD("global db path : %s", db_path_list[1].c_str());
+ LOGD("local db path : %s", db_path_list[0].first.c_str());
+ LOGD("global db path : %s", db_path_list[1].first.c_str());
}
return db_path_list;
public:
~DBHandleProvider() = default;
static DBHandleProvider& GetInst(uid_t uid);
- std::vector<std::string> GetParserDBPath(int pid);
+ std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid);
std::string GetCertDBPath(int pid);
void SetMemoryMode(int pid, bool flag);
return PMINFO_R_ERROR;
}
GList *list = nullptr;
- std::vector<sqlite3*> conn_list = GetConnection();
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
int ret = PMINFO_R_OK;
for (auto& conn : conn_list) {
ret = pkginfo_internal_filter_get_depends_on(
- conn, pkgid_.c_str(), &list);
+ conn.first, pkgid_.c_str(), &list);
if (ret == PMINFO_R_ERROR)
break;
}
GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, __free_packages);
- std::vector<sqlite3*> conn_list = GetConnection();
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
int ret = PMINFO_R_OK;
for (auto& conn : conn_list) {
- ret = pkginfo_internal_filter_get_list(conn, filter_, uid_,
+ ret = pkginfo_internal_filter_get_list(conn.first, filter_, conn.second,
GetLocale().c_str(), list);
if (ret == PMINFO_R_ERROR) {
_LOGE("Failed to pkginfo_internal_filter_get_list (%d)", ret);
int ret = 0;
DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true);
- std::vector<sqlite3*> conn_list = GetConnection();
- sqlite3* conn = conn_list.front();
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
+ sqlite3* conn = conn_list.front().first;
if (write_type_ == Insert) {
ret = pkgmgr_parser_insert_pkg_info(conn, package_, uid_);
} else if (write_type_ == Update) {
}
int ret = PMINFO_R_ERROR;
- std::vector<sqlite3*> conn_list = GetConnection();
+ std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
if (GetOpType() == OPERATION_TYPE_READ) {
for (auto& conn : conn_list) {
- ret = get_query_result(conn, query_[0].c_str(), &list, &row, &col);
+ ret = get_query_result(conn.first, query_[0].c_str(), &list, &row, &col);
if (ret == PMINFO_R_ERROR) {
_LOGE("Failed to execute query");
return ret;
queries[i++] = query.c_str();
for (auto& conn : conn_list) {
- ret = execute_write_queries(conn, queries, query_.size());
+ ret = execute_write_queries(conn.first, queries, query_.size());
// TODO: error check?
}
free(queries);
ret = _pkginfo_get_packages(db, uid, locale, filter,
PMINFO_PKGINFO_GET_ALL, pkginfo_list);
- if (ret == PMINFO_R_OK && uid != GLOBAL_USER)
- ret = _pkginfo_get_packages(db, GLOBAL_USER, locale, filter,
- PMINFO_PKGINFO_GET_ALL, pkginfo_list);
-
return ret;
}