From 37728c74c4a7957d18aeda51c045117e85146e08 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Tue, 12 Apr 2016 13:09:32 +0200 Subject: [PATCH] Mount install steps Mount install is run by "-w $pkgid" option. Mount install, update mount install and deinstallation of mount-installed package should work. Requires: - https://review.tizen.org/gerrit/#/c/65361/ Change-Id: Ie5f6e238160861097359bcb5066b81365e806709 --- src/hybrid/hybrid_installer.cc | 80 ++++++++++++ src/wgt/CMakeLists.txt | 2 + .../step_wgt_prepare_package_directory.cc | 74 ++++++++++++ .../step_wgt_prepare_package_directory.h | 45 +++++++ .../step_wgt_update_package_directory.cc | 134 +++++++++++++++++++++ .../filesystem/step_wgt_update_package_directory.h | 33 +++++ src/wgt/wgt_app_query_interface.cc | 3 +- src/wgt/wgt_installer.cc | 70 +++++++++++ 8 files changed, 440 insertions(+), 1 deletion(-) create mode 100644 src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc create mode 100644 src/wgt/step/filesystem/step_wgt_prepare_package_directory.h create mode 100644 src/wgt/step/filesystem/step_wgt_update_package_directory.cc create mode 100644 src/wgt/step/filesystem/step_wgt_update_package_directory.h diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 9727c54..e6ea1fa 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,11 @@ #include #include #include +#include #include +#include +#include +#include #include #include #include @@ -48,6 +53,8 @@ #include #include +#include +#include #include "hybrid/hybrid_backend_data.h" #include "hybrid/step/configuration/step_merge_tpk_config.h" @@ -121,6 +128,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -153,6 +161,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -181,6 +190,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -219,6 +229,76 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(pkgmgr_); AddStep(); break; + case ci::RequestType::MountInstall: + AddStep(pkgmgr_); + AddStep(); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, + ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); + AddStep(true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::Plugin::ActionType::Install); + AddStep(); + AddStep(); + AddStep(); + break; + case ci::RequestType::MountUpdate: + AddStep(pkgmgr_); + AddStep(); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::PACKAGE, + ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); + AddStep(true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, + ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::Plugin::ActionType::Upgrade); + break; default: AddStep(); break; diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index 5ab8b00..41de461 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -7,7 +7,9 @@ SET(SRCS step/filesystem/step_create_symbolic_link.cc step/filesystem/step_wgt_patch_icons.cc step/filesystem/step_wgt_patch_storage_directories.cc + step/filesystem/step_wgt_prepare_package_directory.cc step/filesystem/step_wgt_resource_directory.cc + step/filesystem/step_wgt_update_package_directory.cc step/pkgmgr/step_generate_xml.cc step/rds/step_wgt_rds_modify.cc step/security/step_add_default_privileges.cc diff --git a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc new file mode 100644 index 0000000..fc4907b --- /dev/null +++ b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2016 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/filesystem/step_wgt_prepare_package_directory.h" + +#include +#include +#include + +#include +#include + +namespace bf = boost::filesystem; +namespace bs = boost::system; +namespace ci = common_installer; + +namespace { + +const char kResWgtDirectory[] = "res/wgt"; + +} // namespace + +namespace wgt { +namespace filesystem { + +ci::Step::Status StepWgtPreparePackageDirectory::CreateSymlinkToMountPoint() { + bs::error_code error; + bf::path mount_point = ci::GetMountLocation(context_->pkg_path.get()); + bf::path res_wgt_link = context_->pkg_path.get() / kResWgtDirectory; + if (bf::exists(res_wgt_link)) { + if (!bf::is_symlink(res_wgt_link)) { + LOG(ERROR) << res_wgt_link << " is not symlink. Cannot proceed"; + return Status::APP_DIR_ERROR; + } + bf::remove(res_wgt_link, error); + if (error) { + LOG(ERROR) << "Failed to remote old symlink to wgt resource directory"; + return Status::APP_DIR_ERROR; + } + } else { + bf::create_directories(res_wgt_link.parent_path(), error); + if (error) { + LOG(ERROR) << "Failed to create " << kResWgtDirectory << " directory"; + return Status::APP_DIR_ERROR; + } + } + bf::create_symlink(mount_point, res_wgt_link, error); + if (error) { + LOG(ERROR) << "Failed to create symlink to widget image"; + return Status::APP_DIR_ERROR; + } + return Status::OK; +} + +ci::Step::Status StepWgtPreparePackageDirectory::process() { + Status status = CreateSymlinkToMountPoint(); + if (status != Status::OK) + return status; + LOG(DEBUG) << "Symlink to mount point created"; + + return Status::OK; +} + +ci::Step::Status StepWgtPreparePackageDirectory::precheck() { + if (context_->pkg_path.get().empty()) { + LOG(ERROR) << "Package installation path is not set"; + return Status::INVALID_VALUE; + } + return Status::OK; +} + +} // namespace filesystem +} // namespace wgt diff --git a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.h b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.h new file mode 100644 index 0000000..6d35f30 --- /dev/null +++ b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.h @@ -0,0 +1,45 @@ +// Copyright (c) 2016 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_FILESYSTEM_STEP_WGT_PREPARE_PACKAGE_DIRECTORY_H_ +#define WGT_STEP_FILESYSTEM_STEP_WGT_PREPARE_PACKAGE_DIRECTORY_H_ + +#include + +#include +#include + +#include + +#include "common/installer_context.h" +#include "common/step/step.h" + +namespace wgt { +namespace filesystem { + +/** + * \brief Responsible for adjusting package directory after mounting zip package + * by StepMountInstall or StepMountUpdate + * + * This step will preserve old application symlinks in bin/ directory. + */ +class StepWgtPreparePackageDirectory : public common_installer::Step { + public: + using Step::Step; + + Status process() override; + Status clean() override { return Status::OK; } + Status undo() override { return Status::OK; } + Status precheck() override; + + private: + Status CreateSymlinkToMountPoint(); + + SCOPE_LOG_TAG(WgtPreparePackageDirectory) +}; + +} // namespace filesystem +} // namespace wgt + +#endif // WGT_STEP_FILESYSTEM_STEP_WGT_PREPARE_PACKAGE_DIRECTORY_H_ diff --git a/src/wgt/step/filesystem/step_wgt_update_package_directory.cc b/src/wgt/step/filesystem/step_wgt_update_package_directory.cc new file mode 100644 index 0000000..0aadad5 --- /dev/null +++ b/src/wgt/step/filesystem/step_wgt_update_package_directory.cc @@ -0,0 +1,134 @@ +// Copyright (c) 2016 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/filesystem/step_wgt_update_package_directory.h" + +#include +#include +#include + +#include +#include + +namespace bf = boost::filesystem; +namespace bs = boost::system; +namespace ci = common_installer; + +namespace { + +const char* kBackupEntries[] = { + "bin", + "shared/res" +}; + +bool MoveCreateDir(const bf::path& source, const bf::path& destination) { + if (!bf::exists(destination.parent_path())) { + bs::error_code error; + bf::create_directories(destination.parent_path(), error); + if (error) { + LOG(ERROR) << "Cannot create directory: " << destination.parent_path(); + return false; + } + } + if (!ci::MoveDir(source, destination)) { + LOG(ERROR) << "Failed to move directory " << destination; + return false; + } + return true; +} + +} // namespace + +namespace wgt { +namespace filesystem { + +ci::Step::Status +StepWgtUpdatePackageDirectory::CreateBackupOfDirectories() { + bf::path backup_path = + ci::GetBackupPathForPackagePath(context_->pkg_path.get()); + for (auto& entry : kBackupEntries) { + bf::path directory = context_->pkg_path.get() / entry; + if (!bf::exists(directory)) + continue; + LOG(DEBUG) << "Backup directory entry: " << entry; + bf::path directory_backup = backup_path / entry; + if (!MoveCreateDir(directory, directory_backup)) { + LOG(ERROR) << "Failed to create backup directory " + << directory_backup; + return Status::APP_DIR_ERROR; + } + } + return Status::OK; +} + +ci::Step::Status +StepWgtUpdatePackageDirectory::RecoverBackupOfDirectories() { + bf::path backup_path = + ci::GetBackupPathForPackagePath(context_->pkg_path.get()); + + // skip if there is no backup of directories + if (!bf::exists(backup_path)) + return Status::OK; + + for (auto& entry : kBackupEntries) { + bf::path directory = context_->pkg_path.get() / entry; + bf::path directory_backup = backup_path / entry; + if (!bf::exists(directory_backup)) + continue; + LOG(DEBUG) << "Recover directory entry: " << entry; + if (!ci::MoveDir(directory_backup, directory)) { + LOG(ERROR) << "Failed to restore directory backup " + << directory_backup; + return Status::APP_DIR_ERROR; + } + } + return Status::OK; +} + +ci::Step::Status StepWgtUpdatePackageDirectory::process() { + auto status = CreateBackupOfDirectories(); + if (status != Status::OK) + return status; + LOG(DEBUG) << "Directory backups created"; + + status = StepWgtPreparePackageDirectory::process(); + if (status != Status::OK) + return status; + + return Status::OK; +} + +ci::Step::Status StepWgtUpdatePackageDirectory::clean() { + bf::path backup_path = + ci::GetBackupPathForPackagePath(context_->pkg_path.get()); + if (bf::exists(backup_path)) { + bs::error_code error; + bf::remove_all(backup_path, error); + if (error) { + LOG(ERROR) << "Failed to remove backup directories"; + return Status::APP_DIR_ERROR; + } + } + return Status::OK; +} + +ci::Step::Status StepWgtUpdatePackageDirectory::undo() { + Status status = RecoverBackupOfDirectories(); + if (status != Status::OK) + return status; + bf::path backup_path = + ci::GetBackupPathForPackagePath(context_->pkg_path.get()); + if (bf::exists(backup_path)) { + bs::error_code error; + bf::remove_all(backup_path, error); + if (error) { + LOG(ERROR) << "Failed to remove backup directories"; + return Status::APP_DIR_ERROR; + } + } + return Status::OK; +} + +} // namespace filesystem +} // namespace wgt diff --git a/src/wgt/step/filesystem/step_wgt_update_package_directory.h b/src/wgt/step/filesystem/step_wgt_update_package_directory.h new file mode 100644 index 0000000..aa15c02 --- /dev/null +++ b/src/wgt/step/filesystem/step_wgt_update_package_directory.h @@ -0,0 +1,33 @@ +// Copyright (c) 2016 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_FILESYSTEM_STEP_WGT_UPDATE_PACKAGE_DIRECTORY_H_ +#define WGT_STEP_FILESYSTEM_STEP_WGT_UPDATE_PACKAGE_DIRECTORY_H_ + +#include + +#include "wgt/step/filesystem/step_wgt_prepare_package_directory.h" + +namespace wgt { +namespace filesystem { + +class StepWgtUpdatePackageDirectory : public StepWgtPreparePackageDirectory { + public: + using StepWgtPreparePackageDirectory::StepWgtPreparePackageDirectory; + + Status process() override; + Status undo() override; + Status clean() override; + + private: + Status CreateBackupOfDirectories(); + Status RecoverBackupOfDirectories(); + + SCOPE_LOG_TAG(WgtUpdatePackageDirectory) +}; + +} // namespace filesystem +} // namespace wgt + +#endif // WGT_STEP_FILESYSTEM_STEP_WGT_UPDATE_PACKAGE_DIRECTORY_H_ diff --git a/src/wgt/wgt_app_query_interface.cc b/src/wgt/wgt_app_query_interface.cc index 68da917..02678ee 100644 --- a/src/wgt/wgt_app_query_interface.cc +++ b/src/wgt/wgt_app_query_interface.cc @@ -40,7 +40,8 @@ std::string GetInstallationRequestInfo(int argc, char** argv) { std::string path; for (int i = 0; i < argc; ++i) { if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "-r") || - !strcmp(argv[i], "-d") || !strcmp(argv[i], "-b")) { + !strcmp(argv[i], "-d") || !strcmp(argv[i], "-b") || + !strcmp(argv[i], "-w")) { if (i + 1 < argc) { path = argv[i + 1]; break; diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 1ba2c06..6fdaa51 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -28,7 +29,11 @@ #include #include #include +#include #include +#include +#include +#include #include #include #include @@ -61,7 +66,9 @@ #include "wgt/step/filesystem/step_create_symbolic_link.h" #include "wgt/step/filesystem/step_wgt_patch_icons.h" #include "wgt/step/filesystem/step_wgt_patch_storage_directories.h" +#include "wgt/step/filesystem/step_wgt_prepare_package_directory.h" #include "wgt/step/filesystem/step_wgt_resource_directory.h" +#include "wgt/step/filesystem/step_wgt_update_package_directory.h" #include "wgt/step/pkgmgr/step_generate_xml.h" #include "wgt/step/rds/step_wgt_rds_modify.h" #include "wgt/step/security/step_add_default_privileges.h" @@ -122,6 +129,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -153,6 +161,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -166,6 +175,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -191,6 +201,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -225,6 +236,65 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); break; } + case ci::RequestType::MountInstall: { + AddStep(pkgmgr_); + AddStep(); + AddStep(true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::Plugin::ActionType::Install); + AddStep(); + AddStep(); + break; + } + case ci::RequestType::MountUpdate: { + AddStep(pkgmgr_); + AddStep(); + AddStep(true); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, + ci::configuration::StepParseManifest::StoreLocation::BACKUP); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep( + ci::Plugin::ActionType::Upgrade); + AddStep(); + break; + } default: { AddStep(); } -- 2.7.4