Add StepWgtPatchIcon at ManifestPartialInstall/Update steps 53/211753/4
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 2 Aug 2019 08:30:43 +0000 (17:30 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Fri, 9 Aug 2019 07:23:49 +0000 (16:23 +0900)
Fix Icon path change after manifest partial install/update

Change-Id: I6d8b55e38192a8cb89ac3b7468265d0c7454e092
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/hybrid/hybrid_installer.cc
src/wgt/step/filesystem/step_wgt_patch_icons.cc
src/wgt/step/filesystem/step_wgt_patch_icons.h
src/wgt/wgt_installer.cc

index 4edd226..aaaed4d 100644 (file)
@@ -146,7 +146,7 @@ void HybridInstaller::InstallSteps() {
   AddStep<ci::filesystem::StepCopy>();
   AddStep<ci::filesystem::StepCopyTep>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
@@ -205,7 +205,7 @@ void HybridInstaller::UpdateSteps() {
   AddStep<ci::backup::StepCopyBackup>();
   AddStep<ci::filesystem::StepUpdateTep>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
@@ -301,7 +301,7 @@ void HybridInstaller::DeltaSteps() {
   AddStep<ci::backup::StepCopyBackup>();
   AddStep<ci::filesystem::StepUpdateTep>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
@@ -377,7 +377,7 @@ void HybridInstaller::MountInstallSteps() {
   AddStep<tpk::filesystem::StepTpkPreparePackageDirectory>();
   AddStep<ci::filesystem::StepCopyTep>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
@@ -436,7 +436,7 @@ void HybridInstaller::MountUpdateSteps() {
   AddStep<tpk::filesystem::StepTpkUpdatePackageDirectory>();
   AddStep<ci::filesystem::StepUpdateTep>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
@@ -480,7 +480,7 @@ void HybridInstaller::ManifestDirectInstallSteps() {
   AddStep<ci::security::StepRollbackInstallationSecurity>();
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<wgt::pkgmgr::StepGenerateXml>();
   AddStep<hybrid::pkgmgr::StepMergeXml>();
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
@@ -523,7 +523,7 @@ void HybridInstaller::ManifestDirectUpdateSteps() {
   AddStep<ci::pkgmgr::StepKillApps>();
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<wgt::pkgmgr::StepGenerateXml>();
   AddStep<hybrid::pkgmgr::StepMergeXml>();
   AddStep<tpk::pkgmgr::StepManifestAdjustment>();
@@ -558,6 +558,7 @@ void HybridInstaller::ManifestPartialInstallSteps() {
   AddStep<ci::security::StepPrivilegeCompatibility>(
       ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH);
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(false);
   AddStep<ci::pkgmgr::StepRegisterApplication>();
   AddStep<ci::security::StepRegisterTrustAnchor>(
       ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL);
@@ -591,6 +592,7 @@ void HybridInstaller::ManifestPartialUpdateSteps() {
       ci::security::StepPrivilegeCompatibility::InternalPrivType::BOTH);
   AddStep<ci::pkgmgr::StepKillApps>();
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(false);
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::security::StepRegisterTrustAnchor>(
       ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);
@@ -656,7 +658,7 @@ void HybridInstaller::ReadonlyUpdateInstallSteps() {
   AddStep<ci::filesystem::StepCopy>();
   AddStep<ci::filesystem::StepCopyTep>();
   AddStep<tpk::filesystem::StepTpkPatchIcons>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
index b80263a..89c5b35 100644 (file)
@@ -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<char*>(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<icon_x*>(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<icon_x*>(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<icon_x*>(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<icon_x*>(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;
index 1f478a5..17c351d 100644 (file)
@@ -7,6 +7,7 @@
 
 #include <manifest_parser/utils/logging.h>
 
+#include <common/installer_context.h>
 #include <common/step/step.h>
 
 #include <string>
@@ -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
index 9a74c7b..840bd81 100644 (file)
@@ -152,7 +152,7 @@ void WgtInstaller::InstallSteps() {
   AddStep<ci::filesystem::StepCopyTep>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
   AddStep<wgt::filesystem::StepCreateSymbolicLink>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::security::StepCheckExtensionPrivileges>();
@@ -205,7 +205,7 @@ void WgtInstaller::UpdateSteps() {
   AddStep<ci::filesystem::StepUpdateTep>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
   AddStep<wgt::filesystem::StepCreateSymbolicLink>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<ci::filesystem::StepCopyStorageDirectories>();
@@ -323,7 +323,7 @@ void WgtInstaller::DeltaSteps() {
   AddStep<ci::filesystem::StepUpdateTep>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
   AddStep<wgt::filesystem::StepCreateSymbolicLink>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<ci::filesystem::StepCopyStorageDirectories>();
@@ -392,7 +392,7 @@ void WgtInstaller::MountInstallSteps() {
   AddStep<ci::filesystem::StepCopyTep>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
   AddStep<wgt::filesystem::StepCreateSymbolicLink>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::pkgmgr::StepGenerateXml>();
@@ -443,7 +443,7 @@ void WgtInstaller::MountUpdateSteps() {
   AddStep<ci::filesystem::StepUpdateTep>();
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
   AddStep<wgt::filesystem::StepCreateSymbolicLink>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<ci::filesystem::StepCreateIcons>();
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::security::StepCheckExtensionPrivileges>();
@@ -478,7 +478,7 @@ void WgtInstaller::ManifestDirectInstallSteps() {
   AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
   AddStep<ci::security::StepRollbackInstallationSecurity>();
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<wgt::pkgmgr::StepGenerateXml>();
   AddStep<ci::pkgmgr::StepRegisterApplication>();
   AddStep<ci::security::StepRegisterTrustAnchor>(
@@ -514,7 +514,7 @@ void WgtInstaller::ManifestDirectUpdateSteps() {
   AddStep<ci::pkgmgr::StepKillApps>();
   AddStep<ci::filesystem::StepCopyTep>();
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<wgt::pkgmgr::StepGenerateXml>();
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::security::StepRegisterTrustAnchor>(
@@ -561,7 +561,7 @@ void WgtInstaller::ReadonlyUpdateInstallSteps() {
   AddStep<wgt::filesystem::StepWgtPatchStorageDirectories>();
   AddStep<ci::filesystem::StepCreateStorageDirectories>();
   AddStep<wgt::filesystem::StepCreateSymbolicLink>();
-  AddStep<wgt::filesystem::StepWgtPatchIcons>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(true);
   AddStep<wgt::filesystem::StepCopyPreviewIcons>();
   AddStep<wgt::security::StepCheckExtensionPrivileges>();
   AddStep<wgt::pkgmgr::StepGenerateXml>();
@@ -622,6 +622,7 @@ void WgtInstaller::ManifestPartialInstallSteps() {
       ci::security::StepPrivilegeCompatibility::InternalPrivType::WGT);
   AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(false);
   AddStep<ci::pkgmgr::StepRegisterApplication>();
   AddStep<ci::security::StepRegisterTrustAnchor>(
       ci::security::StepRegisterTrustAnchor::RegisterType::INSTALL);
@@ -648,6 +649,7 @@ void WgtInstaller::ManifestPartialUpdateSteps() {
   AddStep<wgt::security::StepCheckWgtBackgroundCategory>();
   AddStep<ci::pkgmgr::StepKillApps>();
   AddStep<ci::filesystem::StepRemoveGlobalAppSymlinks>();
+  AddStep<wgt::filesystem::StepWgtPatchIcons>(false);
   AddStep<ci::pkgmgr::StepUpdateApplication>();
   AddStep<ci::security::StepRegisterTrustAnchor>(
       ci::security::StepRegisterTrustAnchor::RegisterType::UPDATE);