2 * Copyright (c) 2020 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.
18 #include <pkgmgr_installer_info.h>
20 #include "common/database.hh"
21 #include "common/exception.hh"
22 #include "common/log_private.hh"
23 #include "common/metadata_plugin.hh"
24 #include "common/metadata_type.hh"
28 void MetadataPlugin::AddAppEventArgs(const std::string& pkgid,
29 const std::string& appid, EventType event_type, GList* list) {
30 auto args = new (std::nothrow) AppEventArgs(appid, pkgid, event_type);
31 if (args == nullptr) {
38 metadata_t* md = static_cast<metadata_t*>(iter->data);
39 args->AddMetadata(std::unique_ptr<Metadata>(
40 new (std::nothrow) Metadata(md->key, md->value)));
41 iter = g_list_next(iter);
44 list_.emplace_back(args);
47 void MetadataPlugin::Do() {
52 for (auto& args : list_) {
53 bool ret = StepBackup(args);
60 for (auto& args : list_) {
62 if (args->GetEventType() == EventType::Install) {
63 ret = StepInstall(args);
64 } else if (args->GetEventType() == EventType::Uninstall) {
65 ret = StepUninstall(args);
66 } else if (args->GetEventType() == EventType::Upgrade) {
67 ret = StepUpgrade(args);
78 void MetadataPlugin::Clean() {
82 Database* MetadataPlugin::GetDB() {
86 uid_t MetadataPlugin::GetUid() {
88 pkgmgr_installer_info_get_target_uid(&target_uid);
92 bool MetadataPlugin::Prepare() {
95 if (!db_->IntegrityCheck())
97 db_->BeginTransaction();
98 } catch (Exception& e) {
104 bool MetadataPlugin::StepBackup(const std::unique_ptr<AppEventArgs>& args) {
108 bool MetadataPlugin::StepInstall(const std::unique_ptr<AppEventArgs>& args) {
112 bool MetadataPlugin::StepUninstall(const std::unique_ptr<AppEventArgs>& args) {
116 bool MetadataPlugin::StepUpgrade(const std::unique_ptr<AppEventArgs>& args) {
120 bool MetadataPlugin::StepRestore() {
124 void MetadataPlugin::Post() {
126 db_->EndTransaction();
128 } catch (Exception& e) {
129 _E("Exception(%d) occurs", e.GetErrorCode());
133 void MetadataPlugin::Rollback() {
136 } catch (Exception& e) {
137 _E("Exception(%d) occurs", e.GetErrorCode());
141 void MetadataPlugin::Undo() {
146 for (auto& args : list_) {
147 if (!StepUninstall(args))
148 _E("StepUninstall() is failed");
152 _E("StepRestore() is failed");
157 } // namespace plugin