From 7e65959e6edce7614221498c2ffa9dcabe068bbe Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Tue, 24 Mar 2015 17:12:12 +0100 Subject: [PATCH] [BackupManifest] Added step for update installation Tizen-JIRA: TC-2482 Change-Id: I09cfd57bf0edb9d2851fe49f02b4fdc11202e854 --- src/common/CMakeLists.txt | 1 + src/common/context_installer.h | 3 ++ src/common/step/step_backup_manifest.cc | 77 +++++++++++++++++++++++++++++++++ src/common/step/step_backup_manifest.h | 30 +++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 src/common/step/step_backup_manifest.cc create mode 100644 src/common/step/step_backup_manifest.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index dca15a0..ab76581 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -5,6 +5,7 @@ SET(SRCS pkgmgr_interface.cc pkgmgr_signal.cc security_registration.cc + step/step_backup_manifest.cc step/step_unzip.cc step/step_check_signature.cc step/step_configure.cc diff --git a/src/common/context_installer.h b/src/common/context_installer.h index d82742c..b6a446b 100644 --- a/src/common/context_installer.h +++ b/src/common/context_installer.h @@ -66,6 +66,9 @@ class ContextInstaller { // path to manifest xml file used to register data in databases Property xml_path; + // path to old manifest xml while updating + Property backup_xml_path; + // pkgid used for update or uninstallation processing Property pkgid; diff --git a/src/common/step/step_backup_manifest.cc b/src/common/step/step_backup_manifest.cc new file mode 100644 index 0000000..0d95974 --- /dev/null +++ b/src/common/step/step_backup_manifest.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include "common/step/step_backup_manifest.h" + +#include +#include +#include + +#include +#include + +#include + +#include "utils/file_util.h" +#include "utils/logging.h" + +namespace bf = boost::filesystem; +namespace bs = boost::system; + +namespace common_installer { +namespace backup_manifest { + +Step::Status StepBackupManifest::precheck() { + if (!bf::exists(context_->xml_path.get())) { + LOG(ERROR) << "Xml manifest file does not exist"; + return Status::ERROR; + } +} + +Step::Status StepBackupManifest::process() { + // set backup file path + bf::path backup_xml_path = context_->xml_path.get(); + backup_xml_path = + ".bck"; + context_->backup_xml_path.set(backup_xml_path); + + if (!utils::MoveFile(context_->xml_path.get(), + context_->backup_xml_path.get())) { + LOG(ERROR) << "Failed to make a copy of xml manifest file"; + return Status::ERROR; + } + LOG(DEBUG) << "Manifest backup created"; + return Status::OK; +} + +Step::Status StepBackupManifest::clean() { + bs::error_code error; + bf::remove(context_->backup_xml_path.get(), error); + if (error) { + LOG(WARNING) << "Cannot remove backup manifest file"; + return Status::ERROR; + } + LOG(DEBUG) << "Manifest backup removed"; + return Status::OK; +} + +Step::Status StepBackupManifest::undo() { + if (bf::exists(context_->backup_xml_path.get())) { + bs::error_code error; + bf::remove(context_->xml_path.get(), error); + if (error) { + LOG(ERROR) << "Failed to remove newly generated xml file in revert"; + return Status::ERROR; + } + if (!utils::MoveFile(context_->backup_xml_path.get(), + context_->xml_path.get())) { + LOG(ERROR) << "Failed to revert a content of xml manifest file"; + return Status::ERROR; + } + LOG(DEBUG) << "Manifest reverted from backup"; + } + return Status::OK; +} + +} // namespace backup_manifest +} // namespace common_installer diff --git a/src/common/step/step_backup_manifest.h b/src/common/step/step_backup_manifest.h new file mode 100644 index 0000000..59906f1 --- /dev/null +++ b/src/common/step/step_backup_manifest.h @@ -0,0 +1,30 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef COMMON_STEP_STEP_BACKUP_MANIFEST_H_ +#define COMMON_STEP_STEP_BACKUP_MANIFEST_H_ + +#include "common/context_installer.h" +#include "common/step/step.h" +#include "utils/logging.h" + +namespace common_installer { +namespace backup_manifest { + +class StepBackupManifest : public Step { + public: + using Step::Step; + + Status process() override; + Status clean() override; + Status undo() override; + Status precheck() override; + + SCOPE_LOG_TAG(BackupManifest) +}; + +} // namespace backup_manifest +} // namespace common_installer + +#endif // COMMON_STEP_STEP_BACKUP_MANIFEST_H_ -- 2.7.4