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 "remove_cache_db_handler.hh"
19 #include "cache_flag.hh"
20 #include "db_handle_provider.hh"
22 namespace pkgmgr_server {
25 RemoveCacheDBHandler::RemoveCacheDBHandler(uid_t uid, int pid)
26 : AbstractDBHandler(uid, pid), uid_(uid) {}
28 int RemoveCacheDBHandler::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);
33 database::DBHandleProvider::GetInst(GetUID()).UnsetMemoryMode(GetPID());
36 database::DBHandleProvider::GetInst(GetUID()).TrimCache();
37 return PMINFO_R_ERROR;
40 std::vector<std::pair<sqlite3*, uid_t>> conn_list = GetConnection();
41 auto lock = CacheFlag::GetWriterLock();
42 if (CacheFlag::GetStatus() != CacheFlag::Status::PREPARED)
44 CacheFlag::SetStatus(CacheFlag::Status::PREPARING);
46 for (auto& conn : conn_list) {
47 auto& provider = database::DBHandleProvider::GetInst(conn.second);
48 success = provider.UpdatePendingPackageInfo(conn.first,
49 GetPID(), uid_, GetLocale());
55 CacheFlag::SetStatus(success ?
56 CacheFlag::Status::PREPARED : CacheFlag::Status::UNPREPARED);
61 } // namespace database
62 } // namespace pkgmgr_server