2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "create_db_handler.hh"
21 #include "db_handle_provider.hh"
23 #include "pkgmgrinfo_debug.h"
24 #include "pkgmgrinfo_internal.h"
30 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
33 namespace pkgmgr_server {
36 CreateDBHandler::CreateDBHandler(uid_t uid, int pid)
37 : AbstractDBHandler(uid, pid) {}
39 CreateDBHandler::~CreateDBHandler() {}
41 std::vector<std::vector<std::string>> CreateDBHandler::GetResult() {
42 return std::move(result_);
45 int CreateDBHandler::Execute() {
46 std::unique_lock<std::shared_timed_mutex> u(lock_);
48 if (CreateParserDB() < 0) {
49 LOGE("Failed to create parser db for uid [%d]", GetUID());
50 return PMINFO_R_ERROR;
53 if (GetUID() == GLOBAL_USER || GetUID() == OWNER_ROOT) {
54 if (CreateCertDB() < 0) {
55 LOGE("Failed to create cert db for uid [%d]", GetUID());
56 return PMINFO_R_ERROR;
63 int CreateDBHandler::CreateParserDB() {
64 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
68 return PMINFO_R_ERROR;
70 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
71 sqlite3* conn = conn_list.front().first;
72 uid_t uid = conn_list.front().second;
74 return pkgmgr_parser_internal_initialize_db(conn, uid);
77 int CreateDBHandler::CreateCertDB() {
78 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB);
82 return PMINFO_R_ERROR;
84 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
85 sqlite3* conn = conn_list.front().first;
86 uid_t uid = conn_list.front().second;
88 return pkgmgr_parser_internal_initialize_db(conn, uid);
91 } // namespace database
92 } // namespace pkgmgr_server