From 084e0f52dd8858efc6f56388577188a37ec7317d Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 14 Aug 2015 10:04:49 +0200 Subject: [PATCH] Recovery for tpk backend Change-Id: I8d0ec4bd539cc2227ce582a9c291a87e17b1f2e1 --- src/tpk/CMakeLists.txt | 3 +- src/tpk/step/step_parse.cc | 15 ++++++---- src/tpk/step/step_parse.h | 5 +++- src/tpk/step/step_parse_recovery.cc | 55 +++++++++++++++++++++++++++++++++++++ src/tpk/step/step_parse_recovery.h | 31 +++++++++++++++++++++ src/tpk/tpk_installer.cc | 25 +++++++++++++++-- src/tpk/tpk_installer.h | 1 + 7 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 src/tpk/step/step_parse_recovery.cc create mode 100644 src/tpk/step/step_parse_recovery.h diff --git a/src/tpk/CMakeLists.txt b/src/tpk/CMakeLists.txt index 6b3a2e5..19c3260 100644 --- a/src/tpk/CMakeLists.txt +++ b/src/tpk/CMakeLists.txt @@ -1,7 +1,8 @@ SET(SRCS - step/step_parse.cc step/step_create_symbolic_link.cc step/step_copy_manifest_xml.cc + step/step_parse.cc + step/step_parse_recovery.cc tpk_app_query_interface.cc tpk_installer.cc xml_parser/xml_parser.cc diff --git a/src/tpk/step/step_parse.cc b/src/tpk/step/step_parse.cc index 952120b..9729209 100644 --- a/src/tpk/step/step_parse.cc +++ b/src/tpk/step/step_parse.cc @@ -7,7 +7,6 @@ #include #include "common/context_installer.h" #include "common/step/step.h" -#include "common/utils/logging.h" using std::vector; using std::string; @@ -15,6 +14,7 @@ using xml_parser::XmlParser; using xml_parser::XmlTree; using xml_parser::XmlElement; +namespace bf = boost::filesystem; namespace ci = common_installer; namespace tpk { @@ -93,18 +93,23 @@ Status StepParse::precheck() { return Step::Status::OK; } +bf::path StepParse::LocateConfigFile() const { + boost::filesystem::path path(context_->unpacked_dir_path.get()); + path /= kManifestFileName; + return path; +} + /* process() * Parse tizen-manifest.xml and get the data from it * Store the data into the context_ */ Status StepParse::process() { - boost::filesystem::path mPath(context_->unpacked_dir_path.get()); - mPath /= kManifestFileName; + bf::path m_path = LocateConfigFile(); - LOG(INFO) << "Parse " << mPath.c_str(); + LOG(INFO) << "Parse " << m_path.c_str(); XmlParser parser; - std::unique_ptr tree(parser.ParseAndGetNewTree(mPath.c_str())); + std::unique_ptr tree(parser.ParseAndGetNewTree(m_path.c_str())); if (tree == nullptr) { LOG(ERROR) << "Failure on parsing xml"; return Status::ERROR; diff --git a/src/tpk/step/step_parse.h b/src/tpk/step/step_parse.h index bc79d3a..ab98cc6 100644 --- a/src/tpk/step/step_parse.h +++ b/src/tpk/step/step_parse.h @@ -18,6 +18,9 @@ class StepParse : public common_installer::Step { Status undo() override { return Status::OK; }; Status precheck() override; + protected: + virtual boost::filesystem::path LocateConfigFile() const; + private: bool SetContextByManifestParser(xml_parser::XmlTree* tree); bool SetPkgInfoManifest(manifest_x* m, @@ -25,7 +28,7 @@ class StepParse : public common_installer::Step { bool SetPkgInfoChildren(manifest_x *m, xml_parser::XmlTree *tree, xml_parser::XmlElement* manifest); - SCOPE_LOG_TAG(StepParse) + SCOPE_LOG_TAG(Parse) }; } // namespace parse diff --git a/src/tpk/step/step_parse_recovery.cc b/src/tpk/step/step_parse_recovery.cc new file mode 100644 index 0000000..da0fd29 --- /dev/null +++ b/src/tpk/step/step_parse_recovery.cc @@ -0,0 +1,55 @@ +// 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 "tpk/step/step_parse_recovery.h" + +#include + +#include "common/backup_paths.h" + +namespace bf = boost::filesystem; + +namespace { + +const char kManifestFileName[] = "tizen-manifest.xml"; + +} // namespace + +namespace tpk { +namespace parse { + +common_installer::Step::Status StepParseRecovery::process() { + (void) StepParse::process(); + return Status::OK; +} + + +common_installer::Step::Status StepParseRecovery::precheck() { + if (context_->root_application_path.get().empty()) { + LOG(ERROR) << "Root path of packages in not set"; + return Status::ERROR; + } + if (context_->pkgid.get().empty()) { + LOG(WARNING) << "Pkgid is not set. Parsing skipped"; + return Status::OK; + } + return Status::OK; +} + +boost::filesystem::path StepParseRecovery::LocateConfigFile() const { + context_->pkg_path.set( + context_->root_application_path.get() / context_->pkgid.get()); + bf::path path1 = common_installer::GetBackupPathForPackagePath( + context_->pkg_path.get()) / kManifestFileName; + bf::path path2 = context_->pkg_path.get() / kManifestFileName; + if (bf::exists(path1)) + return path1; + if (bf::exists(path2)) + return path2; + return {}; +} + +} // namespace parse +} // namespace tpk + diff --git a/src/tpk/step/step_parse_recovery.h b/src/tpk/step/step_parse_recovery.h new file mode 100644 index 0000000..9047af5 --- /dev/null +++ b/src/tpk/step/step_parse_recovery.h @@ -0,0 +1,31 @@ +// 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 TPK_STEP_STEP_PARSE_RECOVERY_H_ +#define TPK_STEP_STEP_PARSE_RECOVERY_H_ + +#include + +#include "common/utils/logging.h" +#include "tpk/step/step_parse.h" + +namespace tpk { +namespace parse { + +class StepParseRecovery : public StepParse { + public: + using StepParse::StepParse; + + Status process() override; + Status precheck() override; + + protected: + boost::filesystem::path LocateConfigFile() const override; + + SCOPE_LOG_TAG(ParseRecovery) +}; +} // namespace parse +} // namespace tpk + +#endif // TPK_STEP_STEP_PARSE_RECOVERY_H_ diff --git a/src/tpk/tpk_installer.cc b/src/tpk/tpk_installer.cc index 58ef201..6e15cdd 100644 --- a/src/tpk/tpk_installer.cc +++ b/src/tpk/tpk_installer.cc @@ -12,11 +12,19 @@ #include "common/step/step_fail.h" #include "common/step/step_generate_xml.h" #include "common/step/step_old_manifest.h" +#include "common/step/step_open_recovery_file.h" #include "common/step/step_parse.h" +#include "common/step/step_recover_application.h" +#include "common/step/step_recover_files.h" +#include "common/step/step_recover_icons.h" +#include "common/step/step_recover_manifest.h" +#include "common/step/step_recover_security.h" +#include "common/step/step_recover_storage_directories.h" #include "common/step/step_register_app.h" #include "common/step/step_remove_icons.h" #include "common/step/step_remove_files.h" #include "common/step/step_revoke_security.h" +#include "common/step/step_remove_temporary_directory.h" #include "common/step/step_register_security.h" #include "common/step/step_check_signature.h" #include "common/step/step_unregister_app.h" @@ -27,6 +35,7 @@ #include "tpk/step/step_copy_manifest_xml.h" #include "tpk/step/step_create_symbolic_link.h" #include "tpk/step/step_parse.h" +#include "tpk/step/step_parse_recovery.h" namespace ci = common_installer; @@ -61,8 +70,7 @@ void TpkInstaller::Prepare() { ReinstallSteps(); break; case ci::RequestType::Recovery: - AddStep(); - // TODO(t.iwanek): recovery mode invocation... + RecoverySteps(); break; default: AddStep(); @@ -117,5 +125,18 @@ void TpkInstaller::ReinstallSteps() { AddStep(); } +void TpkInstaller::RecoverySteps() { + AddStep(pkgmgr_); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); +} + } // namespace tpk diff --git a/src/tpk/tpk_installer.h b/src/tpk/tpk_installer.h index f7d723c..83291bd 100644 --- a/src/tpk/tpk_installer.h +++ b/src/tpk/tpk_installer.h @@ -28,6 +28,7 @@ class TpkInstaller : public common_installer::AppInstaller { void UpdateSteps(); void UninstallSteps(); void ReinstallSteps(); + void RecoverySteps(); SCOPE_LOG_TAG(TpkInstaller) }; -- 2.7.4