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"
22 #include "utils/logging.hh"
24 #include "pkgmgrinfo_debug.h"
25 #include "pkgmgrinfo_internal.h"
31 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
34 namespace pkgmgr_server {
37 CreateDBHandler::CreateDBHandler(uid_t uid, int pid)
38 : AbstractDBHandler(uid, pid) {}
40 CreateDBHandler::~CreateDBHandler() {}
42 std::vector<std::vector<std::string>> CreateDBHandler::GetResult() {
43 return std::move(result_);
46 int CreateDBHandler::Execute() {
47 std::unique_lock<std::shared_timed_mutex> u(lock_);
49 if (CreateParserDB() < 0) {
50 LOG(ERROR) << "Failed to create parser db for uid : " << GetUID();
51 return PMINFO_R_ERROR;
54 if (GetUID() == GLOBAL_USER || GetUID() == OWNER_ROOT) {
55 if (CreateCertDB() < 0) {
56 LOG(ERROR) << "Failed to create cert db";
57 return PMINFO_R_ERROR;
64 int CreateDBHandler::CreateParserDB() {
65 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
69 return PMINFO_R_ERROR;
71 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
72 sqlite3* conn = conn_list.front().first;
73 uid_t uid = conn_list.front().second;
75 return pkgmgr_parser_internal_initialize_db(conn, uid);
78 int CreateDBHandler::CreateCertDB() {
79 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB);
83 return PMINFO_R_ERROR;
85 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
86 sqlite3* conn = conn_list.front().first;
87 uid_t uid = conn_list.front().second;
89 return pkgmgr_parser_internal_initialize_db(conn, uid);
92 } // namespace database
93 } // namespace pkgmgr_server