From 3ee79bc5a2c74149f02c6fbd37531fb22f9a0713 Mon Sep 17 00:00:00 2001 From: Arkadiusz Szulakiewicz Date: Mon, 4 Apr 2016 14:40:06 +0200 Subject: [PATCH] Introduce StepWgtRDSModify for wgt-backend Requires: https://review.tizen.org/gerrit/#/c/64662/ Change-Id: I76525d6c908586315c9546513d3378a89f278ba6 --- src/wgt/CMakeLists.txt | 4 +- src/wgt/rds_parser.cc | 61 ------- src/wgt/rds_parser.h | 63 ------- src/wgt/step/rds/step_rds_modify.cc | 226 ------------------------ src/wgt/step/rds/step_rds_modify.h | 88 --------- src/wgt/step/rds/step_rds_parse.cc | 50 ------ src/wgt/step/rds/step_rds_parse.h | 63 ------- src/wgt/step/rds/step_wgt_rds_modify.cc | 23 +++ src/wgt/step/rds/step_wgt_rds_modify.h | 39 ++++ src/wgt/wgt_backend_data.h | 15 -- src/wgt/wgt_installer.cc | 9 +- 11 files changed, 68 insertions(+), 573 deletions(-) delete mode 100644 src/wgt/rds_parser.cc delete mode 100644 src/wgt/rds_parser.h delete mode 100644 src/wgt/step/rds/step_rds_modify.cc delete mode 100644 src/wgt/step/rds/step_rds_modify.h delete mode 100644 src/wgt/step/rds/step_rds_parse.cc delete mode 100644 src/wgt/step/rds/step_rds_parse.h create mode 100644 src/wgt/step/rds/step_wgt_rds_modify.cc create mode 100644 src/wgt/step/rds/step_wgt_rds_modify.h diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index 6dbb9c9..1b515f7 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -1,6 +1,5 @@ # Target - sources SET(SRCS - rds_parser.cc step/configuration/step_parse.cc step/configuration/step_parse_recovery.cc step/encryption/step_encrypt_resources.cc @@ -10,8 +9,7 @@ SET(SRCS step/filesystem/step_wgt_patch_storage_directories.cc step/filesystem/step_wgt_resource_directory.cc step/pkgmgr/step_generate_xml.cc - step/rds/step_rds_modify.cc - step/rds/step_rds_parse.cc + step/rds/step_wgt_rds_modify.cc step/security/step_add_default_privileges.cc step/security/step_check_settings_level.cc step/security/step_check_wgt_background_category.cc diff --git a/src/wgt/rds_parser.cc b/src/wgt/rds_parser.cc deleted file mode 100644 index 9f2fbb7..0000000 --- a/src/wgt/rds_parser.cc +++ /dev/null @@ -1,61 +0,0 @@ -// 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 "wgt/rds_parser.h" - -#include - -namespace { -const char kAdd[] = "#add"; -const char kModify[] = "#modify"; -const char kDelete[] = "#delete"; -} - -namespace wgt { -namespace rds_parser { - -RDSParser::RDSParser(const std::string& path_to_delta) - : path_to_delta_(path_to_delta) {} - -bool RDSParser::Parse() { - std::vector* current_container = nullptr; - std::string line; - - std::ifstream file_to_parse(path_to_delta_); - if (!file_to_parse.is_open()) - return false; - while (getline(file_to_parse, line)) { - if (line.compare(kDelete) == 0) { - current_container = &files_to_delete_; - continue; - } - if (line.compare(kAdd) == 0) { - current_container = &files_to_add_; - continue; - } - if (line.compare(kModify) == 0) { - current_container = &files_to_modify_; - continue; - } - if (current_container) - current_container->push_back(line); - } - file_to_parse.close(); - return true; -} - -const std::vector& RDSParser::files_to_modify() const { - return files_to_modify_; -} - -const std::vector& RDSParser::files_to_add() const { - return files_to_add_; -} - -const std::vector& RDSParser::files_to_delete() const { - return files_to_delete_; -} - -} // namespace rds_parser -} // namespace wgt diff --git a/src/wgt/rds_parser.h b/src/wgt/rds_parser.h deleted file mode 100644 index 7c412d1..0000000 --- a/src/wgt/rds_parser.h +++ /dev/null @@ -1,63 +0,0 @@ -// 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 WGT_RDS_PARSER_H_ -#define WGT_RDS_PARSER_H_ - -#include -#include -namespace wgt { -namespace rds_parser { - -/** - * \brief Parse RDS config file - */ -class RDSParser { - public: - /** - * \brief Explicit constructor - * - * \param path_to_delta path to directory - */ - explicit RDSParser(const std::string& path_to_delta); - - /** - * \brief Parse package xml - * - * \return true if parsing was successful - */ - bool Parse(); - - /** - * \brief Accessor to vector of files to modify - * - * \return files to modify - */ - const std::vector& files_to_modify() const; - - /** - * \brief Accessor to vector of files to add - * - * \return files to add - */ - const std::vector& files_to_add() const; - - /** - * \brief Accessor to vector of files to delete - * - * \return files to delete - */ - const std::vector& files_to_delete() const; - - private: - std::string path_to_delta_; - std::vector files_to_modify_; - std::vector files_to_add_; - std::vector files_to_delete_; -}; - -} // namespace rds_parser -} // namespace wgt - -#endif // WGT_RDS_PARSER_H_ diff --git a/src/wgt/step/rds/step_rds_modify.cc b/src/wgt/step/rds/step_rds_modify.cc deleted file mode 100644 index 83937cf..0000000 --- a/src/wgt/step/rds/step_rds_modify.cc +++ /dev/null @@ -1,226 +0,0 @@ -// 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 "wgt/step/rds/step_rds_modify.h" - -#include - -#include - -#include - -namespace wgt { -namespace rds { - -namespace bf = boost::filesystem; -namespace bs = boost::system; -namespace cu = common_installer; - -StepRDSModify::StepRDSModify(common_installer::InstallerContext* context) - : Step(context), - backend_data_(nullptr) {} - -common_installer::Step::Status StepRDSModify::precheck() { - if (context_->unpacked_dir_path.get().empty()) { - LOG(ERROR) << "unpacked dir path is not set"; - return common_installer::Step::Status::INVALID_VALUE; - } - if (!bf::exists(context_->unpacked_dir_path.get())) { - LOG(ERROR) << "unpacked_dir_path (" - << context_->unpacked_dir_path.get() - << ") path does not exist"; - return common_installer::Step::Status::INVALID_VALUE; - } - if (context_->pkgid.get().empty()) { - LOG(ERROR) << "pkgid is not set"; - return common_installer::Step::Status::PACKAGE_NOT_FOUND; - } - if (!context_->manifest_data.get()) { - LOG(ERROR) << "no manifest info available"; - return common_installer::Step::Status::INVALID_VALUE; - } - // TODO(w.kosowicz): check if config of installed app was encrypted - backend_data_ = static_cast(context_->backend_data.get()); - if (!backend_data_) { - LOG(ERROR) << "no backend data"; - return common_installer::Step::Status::ERROR; - } - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSModify::process() { - LOG(INFO) << "entered process of step modify"; - if (!SetUpTempBackupDir()) { - LOG(ERROR) << "unable to setup temp directory"; - return common_installer::Step::Status::ERROR; - } - context_->pkg_path.set( - context_->root_application_path.get() /context_->pkgid.get()); - bf::path install_path = context_->pkg_path.get() / "res" / "wgt"; - bf::path unzip_path = context_->unpacked_dir_path.get(); - if (!AddFiles(unzip_path, install_path) || - !ModifyFiles(unzip_path, install_path) || - !DeleteFiles(install_path)) { - LOG(ERROR) << "error during file operation"; - return common_installer::Step::Status::ERROR; - } - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSModify::undo() { - RestoreFiles(); - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSModify::clean() { - if (bf::exists(backup_temp_dir_)) - bf::remove_all(backup_temp_dir_); - return common_installer::Step::Status::OK; -} - -bool StepRDSModify::AddFiles(bf::path unzip_path, bf::path install_path) { - LOG(INFO) << "about to add files"; - bs::error_code error; - for (const auto& file : backend_data_->files_to_add.get()) { - if (!PerformBackup(file, Operation::ADD)) { - LOG(ERROR) << "unable to perform backup of added file"; - return false; - } - bf::path temp_install_path(install_path / file); - if (bf::is_directory(temp_install_path)) { - if (!bf::exists(temp_install_path) && - (!cu::CreateDir(temp_install_path))) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - } else { - if (!bf::exists(temp_install_path.parent_path()) && - !cu::CreateDir(temp_install_path.parent_path())) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - bf::path temp_unzip_path(unzip_path / file); - bf::copy_file(temp_unzip_path, temp_install_path, error); - if (error) { - LOG(ERROR) << "unable to add file " << error.message(); - return false; - } - } - } - return true; -} - -bool StepRDSModify::ModifyFiles(bf::path unzip_path, bf::path install_path) { - LOG(INFO) << "about to modify files"; - bs::error_code error; - for (const auto& file : backend_data_->files_to_modify.get()) { - bf::path temp_install_path(install_path / file); - bf::path temp_unzip_path(unzip_path / file); - if (!PerformBackup(file, Operation::MODIFY)) { - LOG(ERROR) << "unable to perform backup of to be modified file"; - return false; - } - bf::copy_file(temp_unzip_path, temp_install_path, - bf::copy_option::overwrite_if_exists, error); - if (error) { - LOG(ERROR) << "unable to modify file " << error.message(); - return false; - } - } - return true; -} - -bool StepRDSModify::DeleteFiles(bf::path install_path) { - LOG(INFO) << "about to delete files"; - bs::error_code error; - for (const auto& file : backend_data_->files_to_delete.get()) { - if (!PerformBackup(file, Operation::DELETE)) { - LOG(ERROR) << "unable to perform backup of to be deleted file"; - return false; - } - bf::remove(install_path / file, error); - if (error) { - LOG(ERROR) <<"unable to delete files " << error.message(); - return false; - } - } - return true; -} - -bool StepRDSModify::SetUpTempBackupDir() { - LOG(INFO) << "about to setup tmp backup dir"; - bs::error_code error; - backup_temp_dir_ = "/tmp/" / - bf::unique_path("%%%%-%%%%-%%%%-%%%%", error); - if (error || !cu::CreateDir(backup_temp_dir_)) { - LOG(ERROR) << "unable to create backup data temp dir"; - return false; - } - - return true; -} - -bool StepRDSModify::PerformBackup(std::string relative_path, - Operation operation) { - if (backup_temp_dir_.empty()) - return false; - if (operation == Operation::DELETE || operation == Operation::MODIFY) { - bf::path app_path = context_->pkg_path.get() / "res" / "wgt"; - bf::path source_path = app_path / relative_path; - if (bf::is_directory(source_path)) { - if (!cu::CreateDir(backup_temp_dir_ / relative_path)) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - } else { - bs::error_code error; - bf::path tmp_dest_path = backup_temp_dir_ / relative_path; - if (!bf::exists((tmp_dest_path).parent_path()) && - (!cu::CreateDir((tmp_dest_path).parent_path()))) { - LOG(ERROR) << "unable to create dir for temp backup data"; - return false; - } - bf::copy_file(source_path, tmp_dest_path, error); - if (error) { - LOG(ERROR) << "unable to backup file: " - << source_path << " : " << error.message(); - return false; - } - } - } - success_modifications_.push_back(std::make_pair(relative_path, operation)); - return true; -} - -void StepRDSModify::RestoreFiles() { - LOG(ERROR) << "error occured about to restore files"; - bf::path app_path(context_->pkg_path.get()); - for (std::pair& modification : - success_modifications_) { - bf::path source_path(backup_temp_dir_ / modification.first); - bf::path destination_path(app_path / modification.first); - if (modification.second == Operation::ADD) { - if (bf::is_directory(source_path)) { - bf::remove_all(destination_path); - } else { - bf::remove(destination_path); - } - } else if (modification.second == Operation::MODIFY) { - bf::copy_file(source_path, destination_path, - bf::copy_option::overwrite_if_exists); - } else { - if (bf::is_directory(source_path)) { - cu::CreateDir(destination_path); - } else { - bf::copy_file(source_path, destination_path, - bf::copy_option::overwrite_if_exists); - } - } - } - // after files are restore delete temporary location - bf::remove_all(backup_temp_dir_); -} - -} // namespace rds -} // namespace wgt diff --git a/src/wgt/step/rds/step_rds_modify.h b/src/wgt/step/rds/step_rds_modify.h deleted file mode 100644 index 31d4c3b..0000000 --- a/src/wgt/step/rds/step_rds_modify.h +++ /dev/null @@ -1,88 +0,0 @@ -// 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 WGT_STEP_RDS_STEP_RDS_MODIFY_H_ -#define WGT_STEP_RDS_STEP_RDS_MODIFY_H_ - -#include -#include -#include -#include -#include - -#include "wgt/wgt_backend_data.h" - -namespace wgt { -namespace rds { - -/** - * \brief Step that apply RDS modification during reinstallation process - */ -class StepRDSModify : public common_installer::Step { - public: - /** - * \brief Explicit constructor - * - * \param context Installer context - */ - explicit StepRDSModify(common_installer::InstallerContext* context); - - /** - * \brief - * - * \return - */ - Status process() override; - - /** - * \brief Remove files from temporary location - * - * \return Status::OK - */ - Status clean() override; - - /** - * \brief Restore files to the state from before RDS installation - * - * \return Status::OK - */ - Status undo() override; - - /** - * \brief - * - * \return Status::ERROR when manifest is missing, pkgid is missing, - * or when path to the unpacked directory is missing or not exist, - * Status::OK otherwise - */ - Status precheck() override; - - private: - enum class Operation { - ADD, - MODIFY, - DELETE - }; - - bool AddFiles(boost::filesystem::path unzip_path, - boost::filesystem::path install_path); - bool ModifyFiles(boost::filesystem::path unzip_path, - boost::filesystem::path install_path); - bool DeleteFiles(boost::filesystem::path install_path); - bool SetUpTempBackupDir(); - void DeleteTempBackupDir(); - bool PerformBackup(std::string relative_path, Operation operation); - void RestoreFiles(); - - WgtBackendData* backend_data_; - std::vector> success_modifications_; - boost::filesystem::path backup_temp_dir_; - std::vector files_to_modify_; - std::vector files_to_add_; - std::vector files_to_delete_; -}; -} // namespace rds -} // namespace wgt - -#endif // WGT_STEP_RDS_STEP_RDS_MODIFY_H_ diff --git a/src/wgt/step/rds/step_rds_parse.cc b/src/wgt/step/rds/step_rds_parse.cc deleted file mode 100644 index 31ce2b4..0000000 --- a/src/wgt/step/rds/step_rds_parse.cc +++ /dev/null @@ -1,50 +0,0 @@ -// 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 "wgt/step/rds/step_rds_parse.h" - -#include - -#include - -#include "wgt/rds_parser.h" -#include "wgt/wgt_backend_data.h" - - -namespace wgt { -namespace rds { - -namespace bf = boost::filesystem; - -common_installer::Step::Status StepRDSParse::precheck() { - bf::path rdsPath(context_->unpacked_dir_path.get() / ".rds_delta"); - if (!bf::exists(rdsPath)) { - LOG(ERROR) << "no rds_delta file"; - return common_installer::Step::Status::INVALID_VALUE; - } - rds_file_path_ = rdsPath; - return common_installer::Step::Status::OK; -} - -common_installer::Step::Status StepRDSParse::process() { - wgt::rds_parser::RDSParser parser(rds_file_path_.native()); - if (!parser.Parse()) { - LOG(ERROR) << "parsing of rds delta failed"; - return common_installer::Step::Status::PARSE_ERROR; - } - - WgtBackendData* backend_data = - static_cast(context_->backend_data.get()); - if (!backend_data) { - LOG(ERROR) << "no wgt backend data available"; - return common_installer::Step::Status::PARSE_ERROR; - } - backend_data->files_to_modify.set(parser.files_to_modify()); - backend_data->files_to_add.set(parser.files_to_add()); - backend_data->files_to_delete.set(parser.files_to_delete()); - return common_installer::Step::Status::OK; -} - -} // namespace rds -} // namespace wgt diff --git a/src/wgt/step/rds/step_rds_parse.h b/src/wgt/step/rds/step_rds_parse.h deleted file mode 100644 index 649df10..0000000 --- a/src/wgt/step/rds/step_rds_parse.h +++ /dev/null @@ -1,63 +0,0 @@ -// 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 WGT_STEP_RDS_STEP_RDS_PARSE_H_ -#define WGT_STEP_RDS_STEP_RDS_PARSE_H_ - -#include - -#include -#include -#include - -namespace wgt { -namespace rds { - -/** - * \brief This step parse .rds_delta file - * - * This is to prepare RDS installation process - */ -class StepRDSParse : public common_installer::Step { - public: - using Step::Step; - - /** - * \brief Parse .rds_delta file - * - * \return Status::ERROR when wgt backend data are missing, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status clean() override { return Status::OK; } - - /** - * \brief Empty method - * - * \return Status::OK - */ - Status undo() override { return Status::OK; } - - /** - * \brief Validate if .rds_delta file exist - * - * \return Status::Error if file not exist, - * Status::OK otherwise - */ - Status precheck() override; - - private: - boost::filesystem::path rds_file_path_; -}; - -} // namespace rds -} // namespace wgt - -#endif // WGT_STEP_RDS_STEP_RDS_PARSE_H_ diff --git a/src/wgt/step/rds/step_wgt_rds_modify.cc b/src/wgt/step/rds/step_wgt_rds_modify.cc new file mode 100644 index 0000000..aa293e9 --- /dev/null +++ b/src/wgt/step/rds/step_wgt_rds_modify.cc @@ -0,0 +1,23 @@ +// Copyright (c) 2016 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 "wgt/step/rds/step_wgt_rds_modify.h" + +#include +#include + +#include +#include +#include + +namespace wgt { +namespace rds { + +std::string StepWgtRDSModify::GetAppPath() { + boost::filesystem::path p = context_->pkg_path.get() / "res" / "wgt"; + return p.string(); +} + +} // namespace rds +} // namespace wgt diff --git a/src/wgt/step/rds/step_wgt_rds_modify.h b/src/wgt/step/rds/step_wgt_rds_modify.h new file mode 100644 index 0000000..f09347d --- /dev/null +++ b/src/wgt/step/rds/step_wgt_rds_modify.h @@ -0,0 +1,39 @@ +// Copyright (c) 2016 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 WGT_STEP_RDS_STEP_WGT_RDS_MODIFY_H_ +#define WGT_STEP_RDS_STEP_WGT_RDS_MODIFY_H_ + +#include +#include +#include + +#include +#include +#include + +#include "common/installer_context.h" + +namespace wgt { +namespace rds { + +/** + * \brief Step that apply RDS modification during reinstallation process + */ +class StepWgtRDSModify : public common_installer::rds::StepRDSModify { + public: + using StepRDSModify::StepRDSModify; + + /** + * \brief return app path + * + * \return std::string + */ + std::string GetAppPath() override; +}; + +} // rds +} // wgt + +#endif // WGT_STEP_RDS_STEP_WGT_RDS_MODIFY_H_ diff --git a/src/wgt/wgt_backend_data.h b/src/wgt/wgt_backend_data.h index 15daa7e..8fdf4a4 100644 --- a/src/wgt/wgt_backend_data.h +++ b/src/wgt/wgt_backend_data.h @@ -21,21 +21,6 @@ namespace wgt { */ class WgtBackendData : public common_installer::BackendData { public: - /** - * \brief Property of vector of files to add - */ - Property> files_to_add; - - /** - * \brief Property of vector of files to modify - */ - Property> files_to_modify; - - /** - * \brief Property of vector of files to delete - */ - Property> files_to_delete; - /** * \brief Property of SettingInfo */ diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index b0a5dea..00624b8 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -51,6 +51,8 @@ #include #include +#include +#include #include "wgt/step/configuration/step_parse.h" #include "wgt/step/configuration/step_parse_recovery.h" @@ -61,8 +63,7 @@ #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h" #include "wgt/step/filesystem/step_wgt_resource_directory.h" #include "wgt/step/pkgmgr/step_generate_xml.h" -#include "wgt/step/rds/step_rds_modify.h" -#include "wgt/step/rds/step_rds_parse.h" +#include "wgt/step/rds/step_wgt_rds_modify.h" #include "wgt/step/security/step_add_default_privileges.h" #include "wgt/step/security/step_check_settings_level.h" #include "wgt/step/security/step_check_wgt_background_category.h" @@ -164,8 +165,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); AddStep(); - AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); break; } -- 2.34.1