From 35604245e23261c1b53835067d13076787f67aed Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 14 Jan 2016 15:14:57 +0100 Subject: [PATCH] Clean up of storage dirs code - fix update in hybrid app installation Fixes some issue in code handling storage directories. Due to requirement of copying wgt's shared/ directory is addition, situation where: - common create storage directories step - create directories for tpk - wgt create storage directories step - create directories for wgt should be changed to: - common create storage directories step - create directories for tpk and wgt - wgt create storage directories step - only patches shared/ directory with widget shared/ before common step Change-Id: I10f94eafbe31497ad5216f1f5e1ce1abf81bbd44 --- src/hybrid/hybrid_installer.cc | 26 ++-- src/wgt/CMakeLists.txt | 3 +- src/wgt/step/step_wgt_copy_storage_directories.cc | 172 --------------------- src/wgt/step/step_wgt_copy_storage_directories.h | 58 ------- .../step/step_wgt_create_storage_directories.cc | 102 ------------ src/wgt/step/step_wgt_create_storage_directories.h | 77 --------- src/wgt/step/step_wgt_patch_storage_directories.cc | 72 +++++++++ src/wgt/step/step_wgt_patch_storage_directories.h | 39 +++++ src/wgt/wgt_installer.cc | 13 +- 9 files changed, 135 insertions(+), 427 deletions(-) delete mode 100644 src/wgt/step/step_wgt_copy_storage_directories.cc delete mode 100644 src/wgt/step/step_wgt_copy_storage_directories.h delete mode 100644 src/wgt/step/step_wgt_create_storage_directories.cc delete mode 100644 src/wgt/step/step_wgt_create_storage_directories.h create mode 100644 src/wgt/step/step_wgt_patch_storage_directories.cc create mode 100644 src/wgt/step/step_wgt_patch_storage_directories.h diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 7e75a28..c8ec5ad 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -43,8 +45,7 @@ #include "wgt/step/step_generate_xml.h" #include "wgt/step/step_remove_encryption_data.h" #include "wgt/step/step_wgt_create_icons.h" -#include "wgt/step/step_wgt_create_storage_directories.h" -#include "wgt/step/step_wgt_copy_storage_directories.h" +#include "wgt/step/step_wgt_patch_storage_directories.h" namespace ci = common_installer; @@ -69,11 +70,12 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); - AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -96,11 +98,12 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); - AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -145,11 +148,12 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); - AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index a1ee89c..7f32240 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -13,8 +13,7 @@ SET(SRCS step/step_rds_modify.cc step/step_wgt_backup_icons.cc step/step_wgt_create_icons.cc - step/step_wgt_create_storage_directories.cc - step/step_wgt_copy_storage_directories.cc + step/step_wgt_patch_storage_directories.cc step/step_wgt_recover_icons.cc step/step_wgt_resource_directory.cc step/step_add_default_privileges.cc diff --git a/src/wgt/step/step_wgt_copy_storage_directories.cc b/src/wgt/step/step_wgt_copy_storage_directories.cc deleted file mode 100644 index fc2e366..0000000 --- a/src/wgt/step/step_wgt_copy_storage_directories.cc +++ /dev/null @@ -1,172 +0,0 @@ -// 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_wgt_copy_storage_directories.h" - -#include -#include -#include - -#include - -namespace bf = boost::filesystem; -namespace bs = boost::system; - -namespace { - -const char kDataLocation[] = "data"; -const char kSharedLocation[] = "shared"; -const char kSharedDataLocation[] = "shared/data"; -const char kSharedTrustedLocation[] = "shared/trusted"; -const char kResWgtSubPath[] = "res/wgt"; -const char kTemporaryData[] = "tmp"; -} // namespace - -namespace wgt { -namespace filesystem { - -common_installer::Step::Status StepWgtCopyStorageDirectories::process() { - Status status = CreatePrivateTmpDir(); - if (status != Status::OK) - return status; - if (!CacheDir()) - return Status::APP_DIR_ERROR; - - int version = context_->manifest_data.get()->api_version[0] - '0'; - if (version < 3) { - LOG(DEBUG) << "Shared directory coping for tizen 2.x"; - return StepCopyStorageDirectories::process(); - } - - LOG(DEBUG) << "Shared directory coping for tizen 3.x"; - status = CopySharedDirectory(); - if (status != Status::OK) - return status; - - return CopyDataDirectory(); -} - -common_installer::Step::Status StepWgtCopyStorageDirectories::undo() { - int version = context_->manifest_data.get()->api_version[0] - '0'; - if (version < 3) { - LOG(DEBUG) << "Shared directory coping for tizen 2.x"; - return StepCopyStorageDirectories::undo(); - } - - UndoSharedDirectory(); - UndoDataDirectory(); - return Status::OK; -} - -void StepWgtCopyStorageDirectories::UndoSharedDirectory() { - if (!MoveAppStorage(context_->pkg_path.get(), - backup_path_, - kSharedDataLocation)) { - LOG(ERROR) << - "Failed to undo moving of shared/data directory for widget in update"; - } - - if (!MoveAppStorage(context_->pkg_path.get(), - backup_path_, - kSharedTrustedLocation)) { - LOG(ERROR) << "Failed to undo moving of shared/trusted directory" - << "for widget in update"; - } -} - -void StepWgtCopyStorageDirectories::UndoDataDirectory() { - if (!MoveAppStorage(context_->pkg_path.get(), - backup_path_, - kDataLocation)) { - LOG(ERROR) - << "Failed to undo moving of private directory for widget in update"; - } -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::HandleWgtSharedDirectory() { - bf::path res_wgt_path = context_->pkg_path.get() / kResWgtSubPath; - bf::path shared_source = res_wgt_path / kSharedLocation; - bf::path shared_destination = context_->pkg_path.get() / kSharedLocation; - - // Move shared if exist in wgt - if (bf::exists(shared_source)) { - if (!common_installer::MoveDir(shared_source, shared_destination)) { - LOG(ERROR) << "Failed to move shared data from res/wgt to shared"; - return Status::ERROR; - } - } - - // Create shared directory if not present yet - if (!bf::exists(shared_destination)) { - bs::error_code error_code; - bf::create_directory(shared_destination, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create shared storage directory"; - return Status::ERROR; - } - } - - // Symlink created shared directory - bs::error_code error_code; - bf::create_symlink(shared_destination, shared_source, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create symbolic link for shared dir" - << boost::system::system_error(error_code).what(); - return Status::ERROR; - } - return Status::OK; -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::CopySharedDirectory() { - Status status = HandleWgtSharedDirectory(); - if (status != Status::OK) - return status; - - if (!MoveAppStorage(backup_path_, - context_->pkg_path.get(), - kSharedDataLocation)) { - LOG(ERROR) << - "Failed to restore shared/data directory for widget in update"; - return Status::ERROR; - } - - if (!MoveAppStorage(backup_path_, - context_->pkg_path.get(), - kSharedTrustedLocation)) { - LOG(ERROR) << - "Failed to restore shared/trusted directory for widget in update"; - return Status::ERROR; - } - - return Status::OK; -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::CopyDataDirectory() { - if (!MoveAppStorage(backup_path_, - context_->pkg_path.get(), - kDataLocation)) { - LOG(ERROR) << "Failed to restore private directory for widget in update"; - return Status::ERROR; - } - return Status::OK; -} - -common_installer::Step::Status -StepWgtCopyStorageDirectories::CreatePrivateTmpDir() { - bs::error_code error_code; - bf::path tmp_path = context_->pkg_path.get() / kTemporaryData; - bf::create_directory(tmp_path, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create private temporary directory for package"; - return Status::ERROR; - } - return Status::OK; -} - -} // namespace filesystem -} // namespace wgt - diff --git a/src/wgt/step/step_wgt_copy_storage_directories.h b/src/wgt/step/step_wgt_copy_storage_directories.h deleted file mode 100644 index 18eac47..0000000 --- a/src/wgt/step/step_wgt_copy_storage_directories.h +++ /dev/null @@ -1,58 +0,0 @@ -// 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_WGT_COPY_STORAGE_DIRECTORIES_H_ -#define WGT_STEP_STEP_WGT_COPY_STORAGE_DIRECTORIES_H_ - -#include - -#include - -namespace wgt { -namespace filesystem { - -/** - * \brief Update installation (WGT). - * Responsible for coping shared and data directories. - * It extends StepCopyStorageDirectories (it adds distinction between - * 2.x and 3.x shared dir handling - */ -class StepWgtCopyStorageDirectories - : public common_installer::filesystem::StepCopyStorageDirectories { - public: - using StepCopyStorageDirectories::StepCopyStorageDirectories; - - /** - * \brief Create shared and private directories, - * and copy/restore widget files to appropriate directory - * - * \return Status::ERROR when failed to create temporary location, - * private temporary location, or failed to restore - * shared/private directory for widget, - * Status::OK otherwise - */ - Status process() override; - - /** - * \brief Move files from shared/private directories back to source directory - * - * \return Status::OK - */ - Status undo() override; - - private: - Status CopySharedDirectory(); - Status CopyDataDirectory(); - Status HandleWgtSharedDirectory(); - void UndoSharedDirectory(); - void UndoDataDirectory(); - Status CreatePrivateTmpDir(); - - SCOPE_LOG_TAG(CopyWgtStorageDirectories) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_COPY_STORAGE_DIRECTORIES_H_ diff --git a/src/wgt/step/step_wgt_create_storage_directories.cc b/src/wgt/step/step_wgt_create_storage_directories.cc deleted file mode 100644 index d50d072..0000000 --- a/src/wgt/step/step_wgt_create_storage_directories.cc +++ /dev/null @@ -1,102 +0,0 @@ -// 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_wgt_create_storage_directories.h" - -#include -#include -#include - -#include - -namespace bf = boost::filesystem; -namespace bs = boost::system; - -namespace { - -const char kSharedLocation[] = "shared"; -const char kResWgtSubPath[] = "res/wgt"; -const char kTemporaryData[] = "tmp"; - -} // namespace - -namespace wgt { -namespace filesystem { - -common_installer::Step::Status StepWgtCreateStorageDirectories::process() { - if (!PrivateDir()) - return Status::APP_DIR_ERROR; - - char version = context_->manifest_data.get()->api_version[0]; - - if ((version-'0') < 3) { - LOG(DEBUG) << "Shared directory preparation for tizen 2.x"; - if (!ShareDir()) - return Status::APP_DIR_ERROR; - } else { - LOG(DEBUG) << "Shared directory preparation for tizen 3.x"; - if (!ShareDirFor3x()) - return Status::APP_DIR_ERROR; - } - - if (!SubShareDir()) - return Status::APP_DIR_ERROR; - - if (!CreatePrivateTmpDir()) - return Status::APP_DIR_ERROR; - - if (!CacheDir()) - return Status::APP_DIR_ERROR; - - return Status::OK; -} - -bool StepWgtCreateStorageDirectories::ShareDirFor2x() { - bs::error_code error_code; - bf::path shared_path = context_->pkg_path.get() / kSharedLocation; - bf::create_directory(shared_path, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create shared directory for widget"; - return false; - } - return true; -} - -bool StepWgtCreateStorageDirectories::ShareDirFor3x() { - bf::path res_wgt_path = context_->pkg_path.get() / kResWgtSubPath; - if (!bf::exists(res_wgt_path / kSharedLocation)) { - if (!ShareDir()) - return false; - } else { - bf::path src = res_wgt_path / kSharedLocation; - bf::path dst = context_->pkg_path.get() / kSharedLocation; - if (!common_installer::MoveDir(src, dst)) { - LOG(ERROR) << "Failed to move shared data from res/wgt to shared"; - return false; - } - - bs::error_code error_code; - bf::create_symlink(dst, src, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create symbolic link for shared dir" - << boost::system::system_error(error_code).what(); - return false; - } - } // else - return true; -} - -bool StepWgtCreateStorageDirectories::CreatePrivateTmpDir() { - bs::error_code error_code; - bf::path tmp_path = context_->pkg_path.get() / kTemporaryData; - bf::create_directory(tmp_path, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create private temporary directory for package"; - return false; - } - return true; -} - -} // namespace filesystem -} // namespace wgt diff --git a/src/wgt/step/step_wgt_create_storage_directories.h b/src/wgt/step/step_wgt_create_storage_directories.h deleted file mode 100644 index 789c5ee..0000000 --- a/src/wgt/step/step_wgt_create_storage_directories.h +++ /dev/null @@ -1,77 +0,0 @@ -// 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_WGT_CREATE_STORAGE_DIRECTORIES_H_ -#define WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ - -#include - -#include - -namespace wgt { -namespace filesystem { - -/** - * \brief Installation (WGT). - * Responsible for creating shared and data directories. - * It extends StepCreateStorageDirectories (it adds distinction between - * 2.x and 3.x shared dir handling - * - * process method implements creation of shared and data directories. - * Depending on tizen required version it can also move "shared" resources - * from ./res/wgt/shared to ./shared dir (and create symlink back - * to ./res/wgt/shared). - * - * StepWgtCreateStorageDirectories works on following directory: - * * TZ_SYS_RW/PKGID (/usr/apps/PKGID) - * * TZ_SER_APPS/PKGID (/{HOME}/apps_rw/PKGID) - */ -class StepWgtCreateStorageDirectories : - public common_installer::filesystem::StepCreateStorageDirectories { - public: - using StepCreateStorageDirectories::StepCreateStorageDirectories; - - /** - * \brief Create shared and private directories - * - * \return Status::ERROR when failed to create temporary location, or - * private temporary location - * 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 Empty method - * - * \return Status::OK - */ - Status precheck() override { return Status::OK; } - - private: - bool ShareDirFor2x(); - bool ShareDirFor3x(); - - bool CreatePrivateTmpDir(); - - SCOPE_LOG_TAG(CreateWgtStorageDirectories) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ diff --git a/src/wgt/step/step_wgt_patch_storage_directories.cc b/src/wgt/step/step_wgt_patch_storage_directories.cc new file mode 100644 index 0000000..c6a7a94 --- /dev/null +++ b/src/wgt/step/step_wgt_patch_storage_directories.cc @@ -0,0 +1,72 @@ +// 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_wgt_patch_storage_directories.h" + +#include +#include +#include + +#include + +namespace bf = boost::filesystem; +namespace bs = boost::system; + +namespace { + +const char kSharedLocation[] = "shared"; +const char kResWgtSubPath[] = "res/wgt"; +const char kTemporaryData[] = "tmp"; + +} // namespace + +namespace wgt { +namespace filesystem { + +common_installer::Step::Status StepWgtPatchStorageDirectories::process() { + if (!CreatePrivateTmpDir()) + return Status::APP_DIR_ERROR; + + char version = context_->manifest_data.get()->api_version[0]; + if ((version-'0') >= 3) { + LOG(DEBUG) << "Copying widget's shared/ directory"; + if (!ShareDirFor3x()) + return Status::APP_DIR_ERROR; + } + + return Status::OK; +} + +bool StepWgtPatchStorageDirectories::ShareDirFor3x() { + bf::path src = context_->pkg_path.get() / kResWgtSubPath / kSharedLocation; + bf::path dst = context_->pkg_path.get() / kSharedLocation; + if (!common_installer::MoveDir(src, dst, + common_installer::FS_MERGE_DIRECTORIES)) { + LOG(ERROR) << "Failed to move shared data from res/wgt to shared"; + return false; + } + + bs::error_code error_code; + bf::create_symlink(dst, src, error_code); + if (error_code) { + LOG(ERROR) << "Failed to create symbolic link for shared dir" + << boost::system::system_error(error_code).what(); + return false; + } + return true; +} + +bool StepWgtPatchStorageDirectories::CreatePrivateTmpDir() { + bs::error_code error_code; + bf::path tmp_path = context_->pkg_path.get() / kTemporaryData; + bf::create_directory(tmp_path, error_code); + if (error_code) { + LOG(ERROR) << "Failed to create private temporary directory for package"; + return false; + } + return true; +} + +} // namespace filesystem +} // namespace wgt diff --git a/src/wgt/step/step_wgt_patch_storage_directories.h b/src/wgt/step/step_wgt_patch_storage_directories.h new file mode 100644 index 0000000..89992df --- /dev/null +++ b/src/wgt/step/step_wgt_patch_storage_directories.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_WGT_PATCH_STORAGE_DIRECTORIES_H_ +#define WGT_STEP_STEP_WGT_PATCH_STORAGE_DIRECTORIES_H_ + +#include +#include + +namespace wgt { +namespace filesystem { + +/** + * \brief Installation (WGT). + * Responsible for copying widgets shared/ directory into package's + * shared/ directory for tizen widget with api version > 3.0 + */ +class StepWgtPatchStorageDirectories : + 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 { return Status::OK; } + + private: + bool ShareDirFor3x(); + bool CreatePrivateTmpDir(); + + SCOPE_LOG_TAG(PatchWgtStorageDirectories) +}; + +} // namespace filesystem +} // namespace wgt + +#endif // WGT_STEP_STEP_WGT_PATCH_STORAGE_DIRECTORIES_H_ diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 6f117b3..54e4bf0 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -51,9 +52,8 @@ #include "wgt/step/step_rds_parse.h" #include "wgt/step/step_remove_encryption_data.h" #include "wgt/step/step_wgt_backup_icons.h" -#include "wgt/step/step_wgt_copy_storage_directories.h" #include "wgt/step/step_wgt_create_icons.h" -#include "wgt/step/step_wgt_create_storage_directories.h" +#include "wgt/step/step_wgt_patch_storage_directories.h" #include "wgt/step/step_wgt_recover_icons.h" #include "wgt/step/step_wgt_resource_directory.h" @@ -79,7 +79,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -102,7 +103,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -151,7 +153,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); -- 2.7.4