From: Ilho Kim Date: Fri, 2 Aug 2019 08:30:43 +0000 (+0900) Subject: Add StepWgtPatchIcon at ManifestPartialInstall/Update steps X-Git-Tag: accepted/tizen/unified/20190812.235632~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F53%2F211753%2F4;p=platform%2Fcore%2Fappfw%2Fwgt-backend.git Add StepWgtPatchIcon at ManifestPartialInstall/Update steps Fix Icon path change after manifest partial install/update Change-Id: I6d8b55e38192a8cb89ac3b7468265d0c7454e092 Signed-off-by: Ilho Kim --- diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index 4edd226..aaaed4d 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -146,7 +146,7 @@ void HybridInstaller::InstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -205,7 +205,7 @@ void HybridInstaller::UpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -301,7 +301,7 @@ void HybridInstaller::DeltaSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -377,7 +377,7 @@ void HybridInstaller::MountInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -436,7 +436,7 @@ void HybridInstaller::MountUpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -480,7 +480,7 @@ void HybridInstaller::ManifestDirectInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -523,7 +523,7 @@ void HybridInstaller::ManifestDirectUpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -558,6 +558,7 @@ void HybridInstaller::ManifestPartialInstallSteps() { AddStep( ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); + AddStep(false); AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL); @@ -591,6 +592,7 @@ void HybridInstaller::ManifestPartialUpdateSteps() { ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH); AddStep(); AddStep(); + AddStep(false); AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE); @@ -656,7 +658,7 @@ void HybridInstaller::ReadonlyUpdateInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); diff --git a/src/wgt/step/filesystem/step_wgt_patch_icons.cc b/src/wgt/step/filesystem/step_wgt_patch_icons.cc index b80263a..89c5b35 100644 --- a/src/wgt/step/filesystem/step_wgt_patch_icons.cc +++ b/src/wgt/step/filesystem/step_wgt_patch_icons.cc @@ -17,7 +17,7 @@ namespace { const char kDefaultIconPath[] = "/usr/share/wgt-backend/default.png"; -bool PatchIcon(icon_x* icon, const bf::path& dst_path) { +bool PatchIcon(icon_x* icon, const bf::path& dst_path, bool make_copy) { if (!icon) return false; bs::error_code error; @@ -31,13 +31,19 @@ bool PatchIcon(icon_x* icon, const bf::path& dst_path) { 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 false; + if (make_copy) { + 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 false; + } + } else { + if (!bf::exists(icon_path)) { + LOG(ERROR) << "Can't find icon in " << icon_path; + return false; + } } if (icon->text) free(const_cast(icon->text)); @@ -46,6 +52,34 @@ bool PatchIcon(icon_x* icon, const bf::path& dst_path) { return true; } +bool GenerateDefaultIcon(const bf::path& icon_path, + application_x* app, bool make_copy) { + bs::error_code error; + if (make_copy) { + bf::copy_file(kDefaultIconPath, icon_path, + bf::copy_option::overwrite_if_exists, error); + if (error) { + LOG(ERROR) << "Failed to create default icon for web application"; + return false; + } + } else { + if (!bf::exists(icon_path)) { + LOG(ERROR) << "Can't find icon in " << icon_path; + return false; + } + } + icon_x* icon = reinterpret_cast(calloc(1, sizeof(icon_x))); + if (!icon) { + LOG(ERROR) << "Out of memory"; + return false; + } + icon->text = strdup(icon_path.c_str()); + icon->lang = strdup(DEFAULT_LOCALE); + app->icon = g_list_append(app->icon, icon); + + return true; +} + } // namespace namespace wgt { @@ -63,7 +97,7 @@ common_installer::Step::Status StepWgtPatchIcons::process() { GListRange(context_->manifest_data.get()->icon)) { bf::path icon_path = common_icon_location / context_->manifest_data.get()->mainapp_id; - if (!PatchIcon(icon, icon_path)) + if (!PatchIcon(icon, icon_path, make_copy_)) return Status::ICON_ERROR; } for (application_x* app : @@ -74,7 +108,7 @@ common_installer::Step::Status StepWgtPatchIcons::process() { // edit icon->text and copy icons to common location for (auto& icon : GListRange(app->icon)) { bf::path icon_path = common_icon_location / app->appid; - if (!PatchIcon(icon, icon_path)) + if (!PatchIcon(icon, icon_path, make_copy_)) return Status::ICON_ERROR; } } else { @@ -82,20 +116,10 @@ common_installer::Step::Status StepWgtPatchIcons::process() { // create default icon if there is no icon at all bf::path icon_path = common_icon_location / app->appid; icon_path += ".png"; - bf::copy_file(kDefaultIconPath, icon_path, - bf::copy_option::overwrite_if_exists, error); - if (error) { + if (!GenerateDefaultIcon(icon_path, app, make_copy_)) { LOG(ERROR) << "Failed to create default icon for web application"; return Status::ICON_ERROR; } - icon_x* icon = reinterpret_cast(calloc(1, sizeof(icon_x))); - if (!icon) { - LOG(ERROR) << "Out of memory"; - return Status::ICON_ERROR; - } - icon->text = strdup(icon_path.c_str()); - icon->lang = strdup(DEFAULT_LOCALE); - app->icon = g_list_append(app->icon, icon); } } return Status::OK; diff --git a/src/wgt/step/filesystem/step_wgt_patch_icons.h b/src/wgt/step/filesystem/step_wgt_patch_icons.h index 1f478a5..17c351d 100644 --- a/src/wgt/step/filesystem/step_wgt_patch_icons.h +++ b/src/wgt/step/filesystem/step_wgt_patch_icons.h @@ -7,6 +7,7 @@ #include +#include #include #include @@ -23,12 +24,18 @@ class StepWgtPatchIcons : public common_installer::Step { public: using Step::Step; + StepWgtPatchIcons(common_installer::InstallerContext* context, bool make_copy) + : Step(context), make_copy_(make_copy) {} + Status process() override; Status undo() override { return Status::OK; } Status clean() override { return Status::OK; } Status precheck() override { return Status::OK; } STEP_NAME(WgtPatchIcons) + + private: + bool make_copy_; }; } // namespace filesystem diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 9a74c7b..840bd81 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -152,7 +152,7 @@ void WgtInstaller::InstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -205,7 +205,7 @@ void WgtInstaller::UpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -323,7 +323,7 @@ void WgtInstaller::DeltaSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -392,7 +392,7 @@ void WgtInstaller::MountInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -443,7 +443,7 @@ void WgtInstaller::MountUpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -478,7 +478,7 @@ void WgtInstaller::ManifestDirectInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep( @@ -514,7 +514,7 @@ void WgtInstaller::ManifestDirectUpdateSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep( @@ -561,7 +561,7 @@ void WgtInstaller::ReadonlyUpdateInstallSteps() { AddStep(); AddStep(); AddStep(); - AddStep(); + AddStep(true); AddStep(); AddStep(); AddStep(); @@ -622,6 +622,7 @@ void WgtInstaller::ManifestPartialInstallSteps() { ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT); AddStep(); AddStep(); + AddStep(false); AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL); @@ -648,6 +649,7 @@ void WgtInstaller::ManifestPartialUpdateSteps() { AddStep(); AddStep(); AddStep(); + AddStep(false); AddStep(); AddStep( ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);