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 "pkg_set_db_handler.hh"
21 #include "cache_flag.hh"
22 #include "db_handle_provider.hh"
23 #include "utils/logging.hh"
25 #include "pkgmgrinfo_debug.h"
26 #include "pkgmgrinfo_internal.h"
28 namespace pkgmgr_server {
31 PkgSetDBHandler::PkgSetDBHandler(uid_t uid, int pid, bool is_offline)
32 : AbstractDBHandler(uid, pid), uid_(uid), is_offline_(is_offline) {}
34 PkgSetDBHandler::~PkgSetDBHandler() {}
36 void PkgSetDBHandler::SetPkgInfo(package_x* package) {
40 void PkgSetDBHandler::SetWriteType(pkgmgr_common::PkgWriteType write_type) {
41 write_type_ = write_type;
44 std::vector<std::vector<std::string>> PkgSetDBHandler::GetResult() {
45 return std::move(result_);
48 int PkgSetDBHandler::Execute() {
49 std::unique_lock<std::shared_mutex> u(lock_);
50 SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE);
51 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
54 return PMINFO_R_ERROR;
56 const auto& db = GetConnection().front().first;
59 if (write_type_ == pkgmgr_common::PkgWriteType::Insert) {
60 ret = pkgmgr_server::internal::InsertPkgInfo(db, package_, uid_);
61 } else if (write_type_ == pkgmgr_common::PkgWriteType::Update) {
62 ret = pkgmgr_server::internal::UpdatePkgInfo(db, package_, uid_);
63 } else if (write_type_ == pkgmgr_common::PkgWriteType::Delete) {
64 ret = pkgmgr_server::internal::DeletePkgInfo(db, package_->package, uid_);
66 LOG(ERROR) << "Unknown db write type";
67 return PMINFO_R_ERROR;
70 if (is_offline_ || ret != PMINFO_R_OK)
73 auto lock = CacheFlag::GetWriterLock();
74 if (CacheFlag::GetStatus() == CacheFlag::Status::PREPARED) {
75 DBHandleProvider::GetInst(uid_).RegisterPendingPackageInfo(db,
76 package_, GetPID(), uid_, GetLocale(), write_type_);
82 } // namespace database
83 } // namespace pkgmgr_server