2 * Copyright (c) 2023 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_all_cache_db_handler.hh"
19 #include "cache_flag.hh"
20 #include "db_handle_provider.hh"
21 #include "utils/logging.hh"
25 uid_t globaluser_uid = -1;
27 uid_t GetGlobalUID() {
28 if (globaluser_uid == (uid_t)-1)
29 globaluser_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
31 return globaluser_uid;
36 namespace pkgmgr_server {
39 RemoveAllCacheDBHandler::RemoveAllCacheDBHandler(uid_t uid, int pid)
40 : AbstractDBHandler(uid, pid), uid_(uid) {}
42 int RemoveAllCacheDBHandler::Execute() {
43 std::unique_lock<std::shared_mutex> u(lock_);
45 auto lock = CacheFlag::GetWriterLock();
46 if (CacheFlag::GetStatus() != CacheFlag::Status::PREPARED)
48 CacheFlag::SetStatus(CacheFlag::Status::PREPARING);
49 database::DBHandleProvider::GetInst(GetUID()).TrimCache();
50 database::DBHandleProvider::GetInst(GetGlobalUID()).TrimCache();
52 CacheFlag::SetStatus(CacheFlag::Status::UNPREPARED);
57 } // namespace database
58 } // namespace pkgmgr_server