From 7bcbb75c241ed6c3bb66d5662b4d0776a989e616 Mon Sep 17 00:00:00 2001 From: Wojciech Kosowicz Date: Tue, 4 Aug 2015 12:11:29 +0200 Subject: [PATCH] [Recovery] StepRecoveryApplication Change-Id: I3999889e1d790095c1cd93282b823ea1ae2ca6b2 --- src/common/CMakeLists.txt | 1 + src/common/step/step_recover_application.cc | 56 +++++++++++++++++++++++++++++ src/common/step/step_recover_application.h | 35 ++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/common/step/step_recover_application.cc create mode 100644 src/common/step/step_recover_application.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 338d845..d3c22d4 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -19,6 +19,7 @@ SET(SRCS step/step_copy_storage_directories.cc step/step_create_storage_directories.cc step/step_generate_xml.cc + step/step_recover_application.cc step/step_recover_files.cc step/step_recover_icons.cc step/step_recover_manifest.cc diff --git a/src/common/step/step_recover_application.cc b/src/common/step/step_recover_application.cc new file mode 100644 index 0000000..2be4f07 --- /dev/null +++ b/src/common/step/step_recover_application.cc @@ -0,0 +1,56 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache-2.0 license that can be +// found in the LICENSE file. + +#include "common/step/step_recover_application.h" + +#include + +#include "common/pkgmgr_registration.h" + +namespace bf = boost::filesystem; + +namespace common_installer { +namespace pkgmgr { + +Step::Status StepRecoverApplication::RecoveryNew() { + if (!SetXmlPaths()) + return Status::OK; + UnregisterAppInPkgmgr(context_->xml_path.get(), context_->pkgid.get(), + context_->uid.get()); + return Status::OK; +} + +Step::Status StepRecoverApplication::RecoveryUpdate() { + if (!SetXmlPaths()) { + LOG(ERROR) << "Some parameters are lacking"; + return Status::ERROR; + } + bf::path xml_path = bf::exists(context_->backup_xml_path.get()) ? + context_->backup_xml_path.get() : context_->xml_path.get(); + UnregisterAppInPkgmgr(xml_path, context_->pkgid.get(), + context_->uid.get()); + if (!RegisterAppInPkgmgr(xml_path, + context_->pkgid.get().c_str(), + context_->certificate_info.get(), + context_->uid.get())) { + LOG(ERROR) << "Unsuccessful app registration"; + return Status::ERROR; + } + return Status::OK; +} + +bool StepRecoverApplication::SetXmlPaths() { + if (context_->pkgid.get().empty()) + return false; + bf::path xml_path = bf::path(getUserManifestPath(context_->uid.get())) + / context_->pkgid.get(); + xml_path += ".xml"; + context_->xml_path.set(xml_path); + xml_path += ".bck"; + context_->backup_xml_path.set(xml_path); + return true; +} + +} // namespace pkgmgr +} // namespace common_installer diff --git a/src/common/step/step_recover_application.h b/src/common/step/step_recover_application.h new file mode 100644 index 0000000..785fbd4 --- /dev/null +++ b/src/common/step/step_recover_application.h @@ -0,0 +1,35 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache-2.0 license that can be +// found in the LICENSE file. + +#ifndef COMMON_STEP_STEP_RECOVER_APPLICATION_H_ +#define COMMON_STEP_STEP_RECOVER_APPLICATION_H_ + +#include "common/context_installer.h" +#include "common/step/step_recovery.h" + +namespace common_installer { +namespace pkgmgr { + +/** + * @brief recovers applications entries in pkgmgr + * + * Part of RecoveryMode. In case of partial installation + * app get unregistered with pkgmgr. In case of unsuccessful + * update app in state before update gets re-registered + */ +class StepRecoverApplication : public recovery::StepRecovery { + public: + using StepRecovery::StepRecovery; + Status RecoveryNew() override; + Status RecoveryUpdate() override; + private: + bool SetXmlPaths(); + + SCOPE_LOG_TAG(RecoverApplication) +}; + +} // namespace pkgmgr +} // namespace common_installer + +#endif // COMMON_STEP_STEP_RECOVER_APPLICATION_H_ -- 2.7.4