From ef5c1f82bf5d0fe3868bd2cf3b2fb67911d5682e Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Mon, 3 Aug 2015 09:39:36 +0200 Subject: [PATCH] [Recovery] StepParseRecovery Change-Id: I4dbe7a22a11d282e35e9c426404a474157663a2e --- src/wgt/CMakeLists.txt | 1 + src/wgt/step/step_parse.cc | 6 ++++- src/wgt/step/step_parse.h | 8 ++++-- src/wgt/step/step_parse_recovery.cc | 50 +++++++++++++++++++++++++++++++++++++ src/wgt/step/step_parse_recovery.h | 39 +++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/wgt/step/step_parse_recovery.cc create mode 100644 src/wgt/step/step_parse_recovery.h diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index 9b0d9ee..d1fd95c 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -6,6 +6,7 @@ SET(SRCS step/step_encrypt_resources.cc step/step_parse.cc step/step_remove_encryption_data.cc + step/step_parse_recovery.cc step/step_rds_parse.cc step/step_rds_modify.cc step/step_wgt_create_icons.cc diff --git a/src/wgt/step/step_parse.cc b/src/wgt/step/step_parse.cc index cb299ae..ca57425 100755 --- a/src/wgt/step/step_parse.cc +++ b/src/wgt/step/step_parse.cc @@ -246,8 +246,12 @@ bool StepParse::FillManifestX(manifest_x* manifest) { return true; } +bool StepParse::LocateConfigFile() { + return StepParse::Check(context_->unpacked_dir_path.get()); +} + common_installer::Step::Status StepParse::process() { - if (!StepParse::Check(context_->unpacked_dir_path.get())) { + if (!LocateConfigFile()) { LOG(ERROR) << "No config.xml"; return common_installer::Step::Status::ERROR; } diff --git a/src/wgt/step/step_parse.h b/src/wgt/step/step_parse.h index 91d4e30..f44dc9e 100644 --- a/src/wgt/step/step_parse.h +++ b/src/wgt/step/step_parse.h @@ -30,6 +30,12 @@ class StepParse : public common_installer::Step { Status undo() override { return Status::OK; } Status precheck() override { return Status::OK; } + protected: + virtual bool LocateConfigFile(); + bool Check(const boost::filesystem::path& widget_path); + + boost::filesystem::path config_; + private: std::set ExtractPrivileges( std::shared_ptr perm_info) const; @@ -45,8 +51,6 @@ class StepParse : public common_installer::Step { bool FillManifestX(manifest_x* manifest); std::unique_ptr parser_; - boost::filesystem::path config_; - bool Check(const boost::filesystem::path& widget_path); SCOPE_LOG_TAG(Parse) }; diff --git a/src/wgt/step/step_parse_recovery.cc b/src/wgt/step/step_parse_recovery.cc new file mode 100644 index 0000000..f1ea001 --- /dev/null +++ b/src/wgt/step/step_parse_recovery.cc @@ -0,0 +1,50 @@ +// 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 "wgt/step/step_parse_recovery.h" + +#include "common/context_installer.h" + +namespace { + +const char kResWgtPath[] = "res/wgt"; + +} + +namespace wgt { +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; +} + +bool StepParseRecovery::LocateConfigFile() { + context_->pkg_path.set( + context_->root_application_path.get() / context_->pkgid.get()); + + if (Check(common_installer::GetBackupPathForPackagePath( + context_->pkg_path.get()) / kResWgtPath)) + return true; + + if (Check(context_->pkg_path.get() / kResWgtPath)) + return true; + + return false; +} + +} // namespace parse +} // namespace wgt diff --git a/src/wgt/step/step_parse_recovery.h b/src/wgt/step/step_parse_recovery.h new file mode 100644 index 0000000..8d7db7c --- /dev/null +++ b/src/wgt/step/step_parse_recovery.h @@ -0,0 +1,39 @@ +// 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 WGT_STEP_STEP_PARSE_RECOVERY_H_ +#define WGT_STEP_STEP_PARSE_RECOVERY_H_ + +#include "common/utils/logging.h" +#include "wgt/step/step_parse.h" + +namespace wgt { +namespace parse { +/** + * @brief The StepParseRecovery class + * Retrievies package information from config.xml during RECOVERY. + * + * Step is used in recovery mode. + * + * Parse config.xml file by guessing possible locations: + * - backup package directory + * - package installation directory + * to get information about widget package to be recovered. + * + */ +class StepParseRecovery : public StepParse { + public: + using StepParse::StepParse; + + Status process() override; + Status precheck() override; + bool LocateConfigFile() override; + + SCOPE_LOG_TAG(ParseRecovery) +}; + +} // namespace parse +} // namespace wgt + +#endif // WGT_STEP_STEP_PARSE_RECOVERY_H_ -- 2.7.4