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_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 (CreateCertDB() < 0) {
55 LOG(ERROR) << "Failed to create cert db";
56 return PMINFO_R_ERROR;
62 int CreateDBHandler::CreateParserDB() {
63 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
67 return PMINFO_R_ERROR;
69 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
70 sqlite3* conn = conn_list.front().first;
71 uid_t uid = conn_list.front().second;
73 return pkgmgr_parser_internal_initialize_db(conn, uid);
76 int CreateDBHandler::CreateCertDB() {
77 if (GetUID() != GLOBAL_USER && GetUID() != OWNER_ROOT)
80 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_CERTDB);
84 return PMINFO_R_ERROR;
86 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
87 sqlite3* conn = conn_list.front().first;
88 uid_t uid = conn_list.front().second;
90 return pkgmgr_parser_internal_initialize_db(conn, uid);
93 } // namespace database
94 } // namespace pkgmgr_server