From fd1343ad0755bf6f939840b62e74b33e43bafcc0 Mon Sep 17 00:00:00 2001 From: Pawel Sikorski Date: Thu, 23 Jul 2015 14:51:56 +0200 Subject: [PATCH] Extending "shared" directory functionality. Tizen 3.x defines new requirement, in which resources located in "res/wgt/shared" folder should be moved to package ./shared directory. Additionally, symbolic link should be created ./res/wgt/shared -> ./shared On the other hand, tizen 2.x applications, should follow old policy (no data movement) Solution: Introduction of derived StepWgtCreateStorageDirectories that adds above functionality. Change-Id: I3de99339f7d1123d9501f94577b9e2a79383511d --- src/common/context_installer.h | 6 +- src/common/step/step_check_signature.cc | 2 +- src/common/step/step_create_storage_directories.cc | 71 +++++++++++++----- src/common/step/step_create_storage_directories.h | 18 +++++ src/common/step/step_unzip.h | 5 ++ src/tpk/step/step_parse.cc | 3 +- src/wgt/CMakeLists.txt | 1 + src/wgt/step/step_parse.cc | 12 +-- .../step/step_wgt_create_storage_directories.cc | 85 ++++++++++++++++++++++ src/wgt/step/step_wgt_create_storage_directories.h | 50 +++++++++++++ src/wgt/wgt_backend.cc | 4 +- 11 files changed, 224 insertions(+), 33 deletions(-) create mode 100644 src/wgt/step/step_wgt_create_storage_directories.cc create mode 100644 src/wgt/step/step_wgt_create_storage_directories.h diff --git a/src/common/context_installer.h b/src/common/context_installer.h index cd18579..0534fd6 100644 --- a/src/common/context_installer.h +++ b/src/common/context_installer.h @@ -24,8 +24,10 @@ namespace common_installer { class ConfigData { public: ConfigData() {} - Property application_name; - Property required_version; + /** version pointed in tag*/ + Property required_api_version; + /** version pointed int tag*/ + Property required_tizen_version; }; class BackendData { diff --git a/src/common/step/step_check_signature.cc b/src/common/step/step_check_signature.cc index 79fe0f6..3a7cc92 100644 --- a/src/common/step/step_check_signature.cc +++ b/src/common/step/step_check_signature.cc @@ -224,7 +224,7 @@ Step::Status StepCheckSignature::process() { // TODO(t.iwanek): refactoring, move to wgt backend bool is_webapp = context_->pkg_type.get() == "wgt"; if (!ValidatePrivilegeLevel(level, is_webapp, - context_->config_data.get().required_version.get().c_str(), + context_->config_data.get().required_api_version.get().c_str(), context_->manifest_data.get()->privileges)) return Status::ERROR; diff --git a/src/common/step/step_create_storage_directories.cc b/src/common/step/step_create_storage_directories.cc index f6d95d6..60e2fb8 100644 --- a/src/common/step/step_create_storage_directories.cc +++ b/src/common/step/step_create_storage_directories.cc @@ -13,36 +13,71 @@ namespace bs = boost::system; namespace { -const char kDataLocation[] = "data"; -const char kSharedLocation[] = "shared"; +const char kData[] = "data"; +const char kShared[] = "shared"; +const char kSharedData[] = "data"; +const char kSharedTrusted[] = "trusted"; -bool CreateStorageDirectoriesForPath(const bf::path& path) { +} // namespace + +namespace common_installer { +namespace create_storage { + +common_installer::Step::Status StepCreateStorageDirectories::process() { + if (!ShareDir()) + return Status::ERROR; + if (!PrivateDir()) + return Status::ERROR; + + return Status::OK; +} + +bool StepCreateStorageDirectories::ShareDir() { bs::error_code error_code; - bf::path data_path = path / kDataLocation; - bf::create_directory(data_path, error_code); - if (error_code) { - LOG(ERROR) << "Failed to create private directory for widget"; - return false; - } - bf::path shared_path = path / kSharedLocation; + bf::path shared_path = context_->pkg_path.get() / kShared; bf::create_directory(shared_path, error_code); if (error_code) { - LOG(ERROR) << "Failed to create shared directory for widget"; + LOG(ERROR) << "Failed to create shared directory for package"; return false; } + + if (!SubShareDir()) + return false; + return true; } -} // namespace +bool StepCreateStorageDirectories::SubShareDir() { + bs::error_code error_code; + bf::path shared_path = context_->pkg_path.get() / kShared; + bf::path shared_trusted_path = shared_path / kSharedTrusted; + bf::create_directory(shared_trusted_path, error_code); + if (error_code) { + LOG(ERROR) << "Failed to create shared/trusted directory for package"; + return false; + } -namespace common_installer { -namespace create_storage { + bf::path shared_data_path = shared_path / kSharedData; + bf::create_directory(shared_data_path, error_code); + if (error_code) { + LOG(ERROR) << "Failed to create shared/data directory for package"; + return false; + } -common_installer::Step::Status StepCreateStorageDirectories::process() { - if (!CreateStorageDirectoriesForPath(context_->pkg_path.get())) - return Status::ERROR; - return Status::OK; + return true; +} + +bool StepCreateStorageDirectories::PrivateDir() { + bs::error_code error_code; + bf::path data_path = context_->pkg_path.get() / kData; + bf::create_directory(data_path, error_code); + if (error_code) { + LOG(ERROR) << "Failed to create private directory for package"; + return false; + } + return true; } + } // namespace create_storage } // namespace common_installer diff --git a/src/common/step/step_create_storage_directories.h b/src/common/step/step_create_storage_directories.h index 44e29b8..d4a4d71 100644 --- a/src/common/step/step_create_storage_directories.h +++ b/src/common/step/step_create_storage_directories.h @@ -11,6 +11,19 @@ namespace common_installer { namespace create_storage { +/** + * \brief Installation. + * Responsible for creating shared and data directories (wgt/tpk) + * + * * process method implements creation of data and shared directories for + * package. + * * Other methods are empty. + * + * CreateStorageDirectories works on below directories: + * * context_->pkg_path.get(), eg: + * * TZ_SYS_RW/PKGID/ (/usr/apps/PKGID/) + * * TZ_SER_APPS/PKGID/ (/{HOME}/apps_rw/PKGID/) + */ class StepCreateStorageDirectories : public common_installer::Step { public: using Step::Step; @@ -20,6 +33,11 @@ class StepCreateStorageDirectories : public common_installer::Step { Status undo() override { return Status::OK; } Status precheck() override { return Status::OK; } + protected: + bool ShareDir(); + bool SubShareDir(); + bool PrivateDir(); + SCOPE_LOG_TAG(CreateStorageDirectories) }; diff --git a/src/common/step/step_unzip.h b/src/common/step/step_unzip.h index bb032b8..b0e8135 100644 --- a/src/common/step/step_unzip.h +++ b/src/common/step/step_unzip.h @@ -23,6 +23,11 @@ namespace unzip { * rough space requirements vs availability. * Since process method unpacks the package to given directory, undo method * removes them. + * + * Unzip unpacks resources to following directory: + * * TZ_SYS_RW/tmpuniquedir (/usr/apps/tmpuniquedir) + * * TZ_SER_APPS/tmpdir (/{HOME}/apps_rw/tmpuniquedir) + * ContextInstaller::unpacked_dir_path points to this location. */ class StepUnzip : public Step { public: diff --git a/src/tpk/step/step_parse.cc b/src/tpk/step/step_parse.cc index 763ac7d..54bfdf1 100644 --- a/src/tpk/step/step_parse.cc +++ b/src/tpk/step/step_parse.cc @@ -147,8 +147,7 @@ bool StepParse::SetContextByManifestParser(XmlTree* tree) { } // set context_ - context_->config_data.get().application_name.set(label->content()); - context_->config_data.get().required_version.set( + context_->config_data.get().required_api_version.set( manifest->attr("api-version")); context_->pkgid.set(manifest->attr("package")); context_->manifest_data.set(static_cast( diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index f2a3be8..19ed590 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -6,6 +6,7 @@ SET(SRCS step/step_parse.cc step/step_rds_parse.cc step/step_rds_modify.cc + step/step_wgt_create_storage_directories.cc step/step_wgt_resource_directory.cc wgt_app_query_interface.cc wgt_backend.cc diff --git a/src/wgt/step/step_parse.cc b/src/wgt/step/step_parse.cc index 791ed2d..92f1420 100755 --- a/src/wgt/step/step_parse.cc +++ b/src/wgt/step/step_parse.cc @@ -291,15 +291,11 @@ common_installer::Step::Status StepParse::process() { if (short_name_set.begin() != short_name_set.end()) short_name = short_name_set.begin()->second; - const std::string& version = wgt_info->version(); + const std::string& tizen_version = wgt_info->version(); const std::string& required_api_version = info->required_version(); - if (manifest->uiapplication->label) { - context_->config_data.get().application_name.set( - std::string(manifest->uiapplication->label->name)); - } - - context_->config_data.get().required_version.set(required_api_version); + context_->config_data.get().required_api_version.set(required_api_version); + context_->config_data.get().required_tizen_version.set(tizen_version); context_->pkgid.set(std::string(manifest->package)); std::shared_ptr perm_info = @@ -327,7 +323,7 @@ common_installer::Step::Status StepParse::process() { LOG(DEBUG) << " id = " << info->id(); LOG(DEBUG) << " name = " << name; LOG(DEBUG) << " short_name = " << short_name; - LOG(DEBUG) << " version = " << version; + LOG(DEBUG) << " tizen_version = " << tizen_version; LOG(DEBUG) << " icon = " << manifest->uiapplication->icon->name; LOG(DEBUG) << " api_version = " << info->required_version(); LOG(DEBUG) << " privileges -["; diff --git a/src/wgt/step/step_wgt_create_storage_directories.cc b/src/wgt/step/step_wgt_create_storage_directories.cc new file mode 100644 index 0000000..ed661b4 --- /dev/null +++ b/src/wgt/step/step_wgt_create_storage_directories.cc @@ -0,0 +1,85 @@ +// 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 "common/utils/file_util.h" + +namespace bf = boost::filesystem; +namespace bs = boost::system; + +namespace { + +const char kSharedLocation[] = "shared"; +const char kResWgt[] = "res/wgt"; + +} // namespace + +namespace wgt { +namespace create_storage { + +common_installer::Step::Status StepWgtCreateStorageDirectories::process() { + if (!PrivateDir()) + return Status::ERROR; + + char rel_version = + context_->config_data.get().required_tizen_version.get().at(0); + + if ((rel_version-'0') < 3) { + LOG(DEBUG) << "Shared directory preparation for tizen 2.x"; + if (!ShareDir()) + return Status::ERROR; + } else { + LOG(DEBUG) << "Shared directory preparation for tizen 3.x"; + if (!ShareDirFor3x()) + return Status::ERROR; + } + + if (!SubShareDir()) + return Status::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() / kResWgt; + 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; +} + +} // namespace create_storage +} // namespace wgt diff --git a/src/wgt/step/step_wgt_create_storage_directories.h b/src/wgt/step/step_wgt_create_storage_directories.h new file mode 100644 index 0000000..3f92a73 --- /dev/null +++ b/src/wgt/step/step_wgt_create_storage_directories.h @@ -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. + +#ifndef WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ +#define WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ + +#include "common/step/step_create_storage_directories.h" +#include "utils/logging.h" + +namespace wgt { +namespace create_storage { + +/** + * \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::create_storage::StepCreateStorageDirectories { + public: + using common_installer::create_storage:: + StepCreateStorageDirectories::StepCreateStorageDirectories; + + Status process() override; + Status clean() override { return Status::OK; } + Status undo() override { return Status::OK; } + Status precheck() override { return Status::OK; } + + private: + bool ShareDirFor2x(); + bool ShareDirFor3x(); + + SCOPE_LOG_TAG(CreateWgtStorageDirectories) +}; + +} // namespace create_storage +} // namespace wgt + +#endif // WGT_STEP_STEP_WGT_CREATE_STORAGE_DIRECTORIES_H_ diff --git a/src/wgt/wgt_backend.cc b/src/wgt/wgt_backend.cc index 4b3dd3d..e196503 100644 --- a/src/wgt/wgt_backend.cc +++ b/src/wgt/wgt_backend.cc @@ -13,7 +13,6 @@ #include "common/step/step_copy.h" #include "common/step/step_copy_backup.h" #include "common/step/step_copy_storage_directories.h" -#include "common/step/step_create_storage_directories.h" #include "common/step/step_generate_xml.h" #include "common/step/step_parse.h" #include "common/step/step_register_app.h" @@ -34,6 +33,7 @@ #include "wgt/step/step_parse.h" #include "wgt/step/step_rds_parse.h" #include "wgt/step/step_rds_modify.h" +#include "wgt/step/step_wgt_create_storage_directories.h" #include "wgt/step/step_wgt_resource_directory.h" #include "wgt/wgt_app_query_interface.h" @@ -59,7 +59,7 @@ int main(int argc, char** argv) { installer.AddStep(); installer.AddStep(); installer.AddStep(); - installer.AddStep(); + installer.AddStep(); installer.AddStep(); installer.AddStep(); installer.AddStep(); -- 2.7.4