From 782d65d706b0bc46e12a2e041a9331893c788f6c Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Mon, 18 Jan 2016 10:31:48 +0100 Subject: [PATCH] Fix icon copying Icons element are receiving full path in StepParse from now for both wgt and tpk backend and all modes. Steps: - StepCreateIcons - StepBackupIcons - StepRecoverIcons - StepRemoveIcons handles icon files only outside package directory (those in: $HOME/.applications/icons/*) Icons within application directories are copied together with whole package directory (StepCopy) and are not managed by those steps. To handle copying icons within package directory new steps are introduced: - StepWgtPatchIcons (copy to $package/shared/res/ from widget content directory) - StepTpkPatchIcons (copy to $package/shared/res/ if they are in different location, e.g. preload apps) Following changes needs to be submitted together: - https://review.tizen.org/gerrit/57258 (wgt-backend) - https://review.tizen.org/gerrit/57257 (app-installers) - https://review.tizen.org/gerrit/57259 (tpk-backend) Verify by: $ /usr/bin/tpk-backend-ut/smoke_test --gtest_filter=SmokeTest.UpdateMode_Tpk $ /usr/bin/tpk-backend-ut/smoke_test --gtest_filter=SmokeTest.InstallationMode_Tpk $ /usr/bin/tpk-backend-ut/smoke_test --gtest_filter=SmokeTest.DeltaMode_Tpk $ /usr/bin/wgt-backend-ut/smoke_test --gtest_filter=SmokeTest.InstallationMode $ /usr/bin/wgt-backend-ut/smoke_test --gtest_filter=SmokeTest.UpdateMode $ /usr/bin/wgt-backend-ut/smoke_test --gtest_filter=SmokeTest.RDSMode $ /usr/bin/wgt-backend-ut/smoke_test --gtest_filter=SmokeTest.DeltaMode $ /usr/bin/wgt-backend-ut/smoke_test --gtest_filter=SmokeTest.UpdateMode_Rollback $ /usr/bin/wgt-backend-ut/smoke_test --gtest_filter=SmokeTest.InstallationMode_Rollback Change-Id: I8c5d3ba513bb47eed571c3363f657eacb429f82f --- src/hybrid/hybrid_installer.cc | 12 ++++--- src/wgt/CMakeLists.txt | 4 +-- src/wgt/step/step_generate_xml.cc | 23 ++------------ src/wgt/step/step_parse.cc | 15 ++++++++- src/wgt/step/step_wgt_backup_icons.cc | 31 ------------------ src/wgt/step/step_wgt_backup_icons.h | 36 --------------------- src/wgt/step/step_wgt_create_icons.cc | 56 --------------------------------- src/wgt/step/step_wgt_create_icons.h | 47 ---------------------------- src/wgt/step/step_wgt_patch_icons.cc | 57 ++++++++++++++++++++++++++++++++++ src/wgt/step/step_wgt_patch_icons.h | 37 ++++++++++++++++++++++ src/wgt/step/step_wgt_recover_icons.cc | 31 ------------------ src/wgt/step/step_wgt_recover_icons.h | 36 --------------------- src/wgt/wgt_app_query_interface.cc | 14 +++++++-- src/wgt/wgt_installer.cc | 26 +++++++++------- 14 files changed, 147 insertions(+), 278 deletions(-) delete mode 100644 src/wgt/step/step_wgt_backup_icons.cc delete mode 100644 src/wgt/step/step_wgt_backup_icons.h delete mode 100644 src/wgt/step/step_wgt_create_icons.cc delete mode 100644 src/wgt/step/step_wgt_create_icons.h create mode 100644 src/wgt/step/step_wgt_patch_icons.cc create mode 100644 src/wgt/step/step_wgt_patch_icons.h delete mode 100644 src/wgt/step/step_wgt_recover_icons.cc delete mode 100644 src/wgt/step/step_wgt_recover_icons.h diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index c8ec5ad..d044c7e 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -33,6 +33,7 @@ #include #include +#include #include "hybrid/hybrid_backend_data.h" #include "hybrid/step/step_encrypt_resources.h" @@ -44,7 +45,7 @@ #include "wgt/step/step_create_symbolic_link.h" #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_patch_icons.h" #include "wgt/step/step_wgt_patch_storage_directories.h" namespace ci = common_installer; @@ -70,8 +71,9 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); - AddStep(); AddStep(); AddStep(); AddStep(); @@ -98,8 +100,9 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); - AddStep(); AddStep(); AddStep(); AddStep(); @@ -148,8 +151,9 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); - AddStep(); AddStep(); AddStep(); AddStep(); diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index 7f32240..b68e08b 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -11,10 +11,8 @@ SET(SRCS step/step_parse_recovery.cc step/step_rds_parse.cc step/step_rds_modify.cc - step/step_wgt_backup_icons.cc - step/step_wgt_create_icons.cc + step/step_wgt_patch_icons.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 wgt_app_query_interface.cc diff --git a/src/wgt/step/step_generate_xml.cc b/src/wgt/step/step_generate_xml.cc index 6be0750..b2090be 100644 --- a/src/wgt/step/step_generate_xml.cc +++ b/src/wgt/step/step_generate_xml.cc @@ -132,30 +132,13 @@ common_installer::Step::Status StepGenerateXml::GenerateApplicationCommonXml( xmlTextWriterEndElement(writer); } - // icon is renamed to if (app->icon) { icon_x* iconx = reinterpret_cast(app->icon->data); - bf::path app_icon = context_->pkg_path.get(); - // TODO(t.iwanek): type should not be used here - if (context_->pkg_type.get() == "wgt") { - app_icon /= "res/wgt"; - } else { - app_icon /= "shared/res"; - } - app_icon /= iconx->text; - bf::path icon = app->appid; - if (app_icon.has_extension()) - icon += app_icon.extension(); - else - icon += bf::path(".png"); - - if (bf::exists(app_icon)) { - xmlTextWriterWriteFormatElement(writer, BAD_CAST "icon", - "%s", BAD_CAST icon.c_str()); - } + xmlTextWriterWriteFormatElement( + writer, BAD_CAST "icon", "%s", BAD_CAST iconx->text); } else { // Default icon setting is role of the platform - LOG(DEBUG) << "Icon was not found in package"; + LOG(DEBUG) << "Icon was not found in application"; } for (image_x* image : GListRange(app->image)) { diff --git a/src/wgt/step/step_parse.cc b/src/wgt/step/step_parse.cc index 392196e..bab1d10 100644 --- a/src/wgt/step/step_parse.cc +++ b/src/wgt/step/step_parse.cc @@ -5,6 +5,8 @@ #include "wgt/step/step_parse.h" +#include + #include #include #include @@ -36,6 +38,8 @@ #include "wgt/wgt_backend_data.h" +namespace bf = boost::filesystem; + namespace { const std::string kManifestVersion = "1.0.0"; @@ -108,13 +112,22 @@ bool StepParse::FillInstallationInfo(manifest_x* manifest) { } bool StepParse::FillIconPaths(manifest_x* manifest) { + std::shared_ptr app_info = + std::static_pointer_cast( + parser_->GetManifestData(app_keys::kTizenApplicationKey)); + if (!app_info) { + LOG(ERROR) << "Application info manifest data has not been found."; + return false; + } std::shared_ptr icons_info = std::static_pointer_cast( parser_->GetManifestData(app_keys::kIconsKey)); if (icons_info.get()) { for (auto& application_icon : icons_info->icons()) { icon_x* icon = reinterpret_cast (calloc(1, sizeof(icon_x))); - icon->text = strdup(application_icon.path().c_str()); + bf::path icon_path = context_->root_application_path.get() + / app_info->package() / "res" / "wgt" / application_icon.path(); + icon->text = strdup(icon_path.c_str()); icon->lang = strdup(DEFAULT_LOCALE); manifest->icon = g_list_append(manifest->icon, icon); } diff --git a/src/wgt/step/step_wgt_backup_icons.cc b/src/wgt/step/step_wgt_backup_icons.cc deleted file mode 100644 index 5544182..0000000 --- a/src/wgt/step/step_wgt_backup_icons.cc +++ /dev/null @@ -1,31 +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/step_wgt_backup_icons.h" - -#include -#include - -namespace { -const char kSharedRes[] = "shared/res"; - -namespace bf = boost::filesystem; -} // namespace - -namespace wgt { -namespace backup { - -common_installer::Step::Status StepWgtBackupIcons::process() { - // TODO(l.wysocki): As a temporary solution this will move icons into two - // destinations respectively {HOME}/.applications/icons, - // and {APP_ROOT}/shared/res, when some project will stop using old - // location ({HOME}/.applications/icons) then it can be removed from here. - std::vector paths { getIconPath(context_->uid.get()), - context_->root_application_path.get() - / context_->pkgid.get() / kSharedRes }; - return MoveIcons(paths); -} - -} // namespace backup -} // namespace wgt diff --git a/src/wgt/step/step_wgt_backup_icons.h b/src/wgt/step/step_wgt_backup_icons.h deleted file mode 100644 index dc62760..0000000 --- a/src/wgt/step/step_wgt_backup_icons.h +++ /dev/null @@ -1,36 +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_STEP_WGT_BACKUP_ICONS_H_ -#define WGT_STEP_STEP_WGT_BACKUP_ICONS_H_ - -#include -#include - -namespace wgt { -namespace backup { - -/** - *\brief Step responsible for creating backup for icons during update and - * uninstallation. - * Used by WGT backend - */ -class StepWgtBackupIcons : public common_installer::backup::StepBackupIcons { - public: - using StepBackupIcons::StepBackupIcons; - - /** - * \brief main logic of backuping icons - * - * \return Status::OK, if successful backup, Status::ERROR otherwise - */ - Status process() override; - - SCOPE_LOG_TAG(WgtBackupIcons) -}; - -} // namespace backup -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_BACKUP_ICONS_H_ diff --git a/src/wgt/step/step_wgt_create_icons.cc b/src/wgt/step/step_wgt_create_icons.cc deleted file mode 100644 index c38f4c7..0000000 --- a/src/wgt/step/step_wgt_create_icons.cc +++ /dev/null @@ -1,56 +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_icons.h" - -#include -#include - -#include "common/utils/glist_range.h" - -namespace bf = boost::filesystem; -namespace ci = common_installer; - -namespace { -const char kResWgt[] = "res/wgt"; -} // namespace - -namespace wgt { -namespace filesystem { - -common_installer::Step::Status StepWgtCreateIcons::process() { - // TODO(l.wysocki): As a temporary solution this will copy icons into two - // destinations respectively {HOME}/.applications/icons, - // and {APP_ROOT}/shared/res, when some project will stop using old - // location ({HOME}/.applications/icons) then it can be removed from here. - std::vector paths { getIconPath(context_->uid.get()), - StepCreateIcons::GetIconRoot() }; - - // explicit step for wgt apps to add absolute path to icon in order to - // store it in db - ci::Step::Status result = CopyIcons(paths); - for (application_x* app : - GListRange(context_->manifest_data.get()->application)) { - if (app->icon) { - icon_x* icon = reinterpret_cast(app->icon->data); - bf::path icon_path = StepCreateIcons::GetIconRoot() / icon->text; - if (icon->text) - free(const_cast(icon->text)); - icon->text = strdup(icon_path.c_str()); - } - } - return result; -} - -boost::filesystem::path StepWgtCreateIcons::GetIconRoot() const { - return context_->pkg_path.get() / kResWgt; -} - -std::string StepWgtCreateIcons::GetAppTypeForIcons() const { - return "webapp"; -} - -} // namespace filesystem -} // namespace wgt - diff --git a/src/wgt/step/step_wgt_create_icons.h b/src/wgt/step/step_wgt_create_icons.h deleted file mode 100644 index a9501a3..0000000 --- a/src/wgt/step/step_wgt_create_icons.h +++ /dev/null @@ -1,47 +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_ICONS_H_ -#define WGT_STEP_STEP_WGT_CREATE_ICONS_H_ - -#include - -#include - -#include - -namespace wgt { -namespace filesystem { - -/** - * \brief This step return path to widget icon - */ -class StepWgtCreateIcons - : public common_installer::filesystem::StepCreateIcons { - public: - using StepCreateIcons::StepCreateIcons; - - Status process() override; - - /** - * \brief Return path to widget icon - * - * \return path to widget icon - */ - boost::filesystem::path GetIconRoot() const override; - - /** - * \brief Return type of application for which icons should be created - * - * \return application type - */ - std::string GetAppTypeForIcons() const override; - - SCOPE_LOG_TAG(WgtCreateIcons) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_CREATE_ICONS_H_ diff --git a/src/wgt/step/step_wgt_patch_icons.cc b/src/wgt/step/step_wgt_patch_icons.cc new file mode 100644 index 0000000..45da3de --- /dev/null +++ b/src/wgt/step/step_wgt_patch_icons.cc @@ -0,0 +1,57 @@ +// 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_icons.h" + +#include + +#include "common/utils/file_util.h" +#include "common/utils/glist_range.h" + +namespace bf = boost::filesystem; +namespace bs = boost::system; +namespace ci = common_installer; + +namespace { +const char kResWgt[] = "res/wgt"; +} // namespace + +namespace wgt { +namespace filesystem { + +common_installer::Step::Status StepWgtPatchIcons::process() { + bf::path common_icon_location = context_->pkg_path.get() / "shared" / "res"; + bs::error_code error; + bf::create_directories(common_icon_location, error); + for (application_x* app : + GListRange(context_->manifest_data.get()->application)) { + if (strcmp(app->type, "webapp") != 0) + continue; + if (app->icon) { + icon_x* icon = reinterpret_cast(app->icon->data); + bf::path icon_text(icon->text); + bf::path icon_path = common_icon_location / app->appid; + if (icon_text.has_extension()) + icon_path += icon_text.extension(); + else + icon_path += ".png"; + + bf::copy_file(icon->text, icon_path, + bf::copy_option::overwrite_if_exists, error); + if (error) { + LOG(ERROR) << "Failed to move icon from " << icon->text << " to " + << icon_path; + return Status::ICON_ERROR; + } + if (icon->text) + free(const_cast(icon->text)); + icon->text = strdup(icon_path.c_str()); + } + } + return Status::OK; +} + +} // namespace filesystem +} // namespace wgt + diff --git a/src/wgt/step/step_wgt_patch_icons.h b/src/wgt/step/step_wgt_patch_icons.h new file mode 100644 index 0000000..c5eabaa --- /dev/null +++ b/src/wgt/step/step_wgt_patch_icons.h @@ -0,0 +1,37 @@ +// 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_ICONS_H_ +#define WGT_STEP_STEP_WGT_PATCH_ICONS_H_ + +#include + +#include + +#include + +namespace wgt { +namespace filesystem { + +/** + * @brief The StepWgtPatchIcons class + * Copy widget icons to standard location of icons - shared/res/ + * where StepCreateIcons excepts icons to be. + */ +class StepWgtPatchIcons : public common_installer::Step { + public: + using Step::Step; + + Status process() override; + Status undo() override { return Status::OK; } + Status clean() override { return Status::OK; } + Status precheck() override { return Status::OK; } + + SCOPE_LOG_TAG(WgtPatchIcons) +}; + +} // namespace filesystem +} // namespace wgt + +#endif // WGT_STEP_STEP_WGT_PATCH_ICONS_H_ diff --git a/src/wgt/step/step_wgt_recover_icons.cc b/src/wgt/step/step_wgt_recover_icons.cc deleted file mode 100644 index 995e609..0000000 --- a/src/wgt/step/step_wgt_recover_icons.cc +++ /dev/null @@ -1,31 +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_recover_icons.h" - -#include - -namespace { -const char kSharedRes[] = "shared/res"; - -namespace bf = boost::filesystem; -} // namespace - -namespace wgt { -namespace filesystem { - -std::vector StepWgtRecoverIcons::GetIconsPaths() { - // TODO(l.wysocki): As a temporary solution this will move icons into two - // destinations respectively {HOME}/.applications/icons, - // and {APP_ROOT}/shared/res, when some project will stop using old - // location ({HOME}/.applications/icons) then it can be removed from here. - std::vector paths { bf::path(getIconPath(context_->uid.get())), - context_->root_application_path.get() - / context_->pkgid.get() / kSharedRes }; - return paths; -} - -} // namespace filesystem -} // namespace wgt - diff --git a/src/wgt/step/step_wgt_recover_icons.h b/src/wgt/step/step_wgt_recover_icons.h deleted file mode 100644 index 5f88113..0000000 --- a/src/wgt/step/step_wgt_recover_icons.h +++ /dev/null @@ -1,36 +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_RECOVER_ICONS_H_ -#define WGT_STEP_STEP_WGT_RECOVER_ICONS_H_ - -#include -#include - -namespace wgt { -namespace filesystem { - -/** - * @brief The StepRecoverIcons class - * Fixes state of platform icon files in recovery mode. - * - * For recovery of new installation, all icons files are removed. - * For recovery of update installation, all icons of applications of package are - * restored to its previous locations. - */ -class StepWgtRecoverIcons : - public common_installer::filesystem::StepRecoverIcons { - public: - using StepRecoverIcons::StepRecoverIcons; - - protected: - virtual std::vector GetIconsPaths(); - - SCOPE_LOG_TAG(WgtRecoverIcons) -}; - -} // namespace filesystem -} // namespace wgt - -#endif // WGT_STEP_STEP_WGT_RECOVER_ICONS_H_ diff --git a/src/wgt/wgt_app_query_interface.cc b/src/wgt/wgt_app_query_interface.cc index 3f42f71..0dc580d 100644 --- a/src/wgt/wgt_app_query_interface.cc +++ b/src/wgt/wgt_app_query_interface.cc @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -88,6 +89,13 @@ std::string GetPkgIdFromPath(const std::string& path) { return pkg_id; } +std::string ReadPkgidFromRecovery(const std::string& recovery_path) { + std::unique_ptr recovery_file = + ci::recovery::RecoveryFile::OpenRecoveryFileForPath(recovery_path); + recovery_file->Detach(); + return recovery_file->pkgid(); +} + } // namespace namespace wgt { @@ -104,10 +112,12 @@ bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { bool WgtAppQueryInterface::IsHybridApplication(int argc, char** argv) { std::string arg = GetInstallationRequestInfo(argc, argv); + if (arg.find("apps_rw/recovery-") != std::string::npos) + arg = ReadPkgidFromRecovery(arg); if (ci::IsPackageInstalled(arg, ci::GetRequestMode())) { bf::path package_directory(ci::GetRootAppPath()); - if (bf::exists(package_directory / kTizenManifestLocation) && - bf::exists(package_directory / kHybridConfigLocation)) + if (bf::exists(package_directory / arg / kTizenManifestLocation) && + bf::exists(package_directory / arg / kHybridConfigLocation)) return true; } else { bool tizen_manifest_found = false; diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 54e4bf0..c4d5ca9 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -8,7 +8,9 @@ #include #include +#include #include +#include #include #include #include @@ -22,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -51,10 +54,8 @@ #include "wgt/step/step_rds_modify.h" #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_create_icons.h" +#include "wgt/step/step_wgt_patch_icons.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" namespace ci = common_installer; @@ -82,7 +83,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -101,12 +103,13 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); - AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -151,12 +154,13 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); - AddStep(); AddStep(); - AddStep(); + AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -168,7 +172,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); -- 2.7.4