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 "update_pending_cache_handler.hh"
19 #include "cache_flag.hh"
20 #include "db_handle_provider.hh"
22 namespace pkgmgr_server {
25 UpdatePendingCacheHandler::UpdatePendingCacheHandler(uid_t uid, std::unordered_set<pid_t> pids, std::vector<std::string> args)
26 : AbstractDBHandler(uid, 0), uid_(uid), pids_(std::move(pids)), args_(std::move(args)) {}
28 int UpdatePendingCacheHandler::Execute() {
29 std::unique_lock<std::shared_mutex> u(lock_);
30 SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
31 SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
34 database::DBHandleProvider::GetInst(GetUID()).TrimCache();
35 return PMINFO_R_ERROR;
38 const auto& conn_list = GetConnection();
39 auto lock = CacheFlag::GetWriterLock();
40 if (CacheFlag::GetStatus() != CacheFlag::Status::PREPARED)
43 CacheFlag::SetStatus(CacheFlag::Status::PREPARING);
44 for (const auto& [db, uid] : conn_list) {
45 auto& provider = database::DBHandleProvider::GetInst(uid);
47 provider.UpdatePendingPackageInfo(args_);
49 provider.UpdateCrashedWriterPackageInfo(pids_);
52 CacheFlag::SetStatus(CacheFlag::Status::PREPARED);
57 } // namespace database
58 } // namespace pkgmgr_server