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 "cache_db_handler.hh"
19 #include <shared_mutex>
22 #include "cache_flag.hh"
23 #include "db_handle_provider.hh"
24 #include "utils/logging.hh"
26 namespace pkgmgr_server {
29 CacheDBHandler::CacheDBHandler(uid_t uid, int pid)
30 : AbstractDBHandler(uid, pid), uid_(uid) {}
32 CacheDBHandler::~CacheDBHandler() {}
34 int CacheDBHandler::Execute() {
35 std::shared_lock<std::shared_mutex> s(lock_);
36 SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
37 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
40 CacheFlag::SetStatus(CacheFlag::Status::UNPREPARED);
41 return PMINFO_R_ERROR;
44 const auto& conn_list = GetConnection();
45 auto lock = CacheFlag::GetWriterLock();
46 int ret = PMINFO_R_OK;
47 for (const auto& [db, uid] : conn_list) {
48 ret = DBHandleProvider::GetInst(uid)
49 .UpdateCache(db, GetPID(), uid_, false, GetLocale());
50 if (ret != PMINFO_R_OK) {
51 LOG(ERROR) << "Failed to update pkginfo cache : " << ret;
56 CacheFlag::SetStatus(ret == PMINFO_R_OK ?
57 CacheFlag::Status::PREPARED :
58 CacheFlag::Status::UNPREPARED);
63 } // namespace database
64 } // namespace pkgmgr_server