Icons paths parametrization 88/56488/5 accepted/tizen/mobile/20160115.010734 accepted/tizen/mobile/20160115.010911 accepted/tizen/tv/20160115.010746 accepted/tizen/tv/20160115.010928 accepted/tizen/wearable/20160115.010805 accepted/tizen/wearable/20160115.010951 submit/tizen/20160114.141522 submit/tizen/20160114.224350
authorLukasz Wysocki <l.wysocki@samsung.com>
Fri, 8 Jan 2016 11:58:21 +0000 (12:58 +0100)
committerLukasz Wysocki <l.wysocki@samsung.com>
Thu, 14 Jan 2016 12:19:09 +0000 (13:19 +0100)
This change is required to allow temporary copy icon into two
destinations in Web apps.

Associated chages:
- https://review.tizen.org/gerrit/#/c/56489/

Change-Id: Id4a02ad34bbb3b8f58cdd229c63562442e178019

src/common/step/step_backup_icons.cc
src/common/step/step_backup_icons.h
src/common/step/step_create_icons.cc
src/common/step/step_create_icons.h
src/common/step/step_recover_icons.cc
src/common/step/step_recover_icons.h

index 559fd58..717ff0a 100644 (file)
@@ -20,25 +20,49 @@ namespace common_installer {
 namespace backup {
 
 Step::Status StepBackupIcons::process() {
+  std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
+  return MoveIcons(paths);
+}
+
+Step::Status StepBackupIcons::clean() {
+  RemoveBackupIcons();
+  LOG(DEBUG) << "Icons backup removed";
+  return Status::OK;
+}
+
+Step::Status StepBackupIcons::undo() {
+  for (auto& pair : icons_) {
+    if (!MoveFile(pair.second, pair.first)) {
+      LOG(ERROR) << "Cannot revert icon from backup: " << pair.first;
+      return Status::ICON_ERROR;
+    }
+  }
+  LOG(DEBUG) << "Icons reverted from backup";
+  return Status::OK;
+}
+
+Step::Status StepBackupIcons::MoveIcons(
+    const std::vector<boost::filesystem::path>& sources) {
   // gather icon info
   for (application_x* app :
       GListRange<application_x*>(
          context_->old_manifest_data.get()->application)) {
-    bf::path app_icon = bf::path(getIconPath(context_->uid.get()))
-        / bf::path(app->appid);
-    if (app->icon) {
-      icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
-      if (!icon->text) {
-        LOG(ERROR) << "Icon text is not set";
-        return Status::ICON_NOT_FOUND;
+    for (const auto& source : sources) {
+      bf::path source_path = source / bf::path(app->appid);
+      if (app->icon) {
+        icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
+        if (!icon->text) {
+          LOG(ERROR) << "Icon text is not set";
+          return Status::ICON_NOT_FOUND;
+        }
+        source_path += bf::path(icon->text).extension();
+      } else {
+        source_path += ".png";
       }
-      app_icon += bf::path(icon->text).extension();
-    } else {
-      app_icon += ".png";
+      bf::path icon_backup = GetBackupPathForIconFile(source_path);
+      if (bf::exists(source_path))
+          icons_.emplace_back(source_path, icon_backup);
     }
-    bf::path icon_backup = GetBackupPathForIconFile(app_icon);
-    if (bf::exists(app_icon))
-        icons_.emplace_back(app_icon, icon_backup);
   }
 
   // backup
@@ -53,23 +77,6 @@ Step::Status StepBackupIcons::process() {
   return Status::OK;
 }
 
-Step::Status StepBackupIcons::clean() {
-  RemoveBackupIcons();
-  LOG(DEBUG) << "Icons backup removed";
-  return Status::OK;
-}
-
-Step::Status StepBackupIcons::undo() {
-  for (auto& pair : icons_) {
-    if (!MoveFile(pair.second, pair.first)) {
-      LOG(ERROR) << "Cannot revert icon from backup: " << pair.first;
-      return Status::ICON_ERROR;
-    }
-  }
-  LOG(DEBUG) << "Icons reverted from backup";
-  return Status::OK;
-}
-
 void StepBackupIcons::RemoveBackupIcons() {
   for (auto& pair : icons_) {
     bs::error_code error;
index 49de070..6096c4d 100644 (file)
@@ -52,6 +52,9 @@ class StepBackupIcons : public Step {
    */
   Status precheck() override { return Status::OK; }
 
+ protected:
+  Status MoveIcons(const std::vector<boost::filesystem::path>& sources);
+
  private:
   void RemoveBackupIcons();
 
index 5cf1159..1e77c2f 100644 (file)
@@ -17,39 +17,52 @@ namespace common_installer {
 namespace filesystem {
 
 Step::Status StepCreateIcons::process() {
-  bf::path icons_directory(getIconPath(context_->uid.get()));
-  if (!bf::exists(icons_directory)) {
+  std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
+  return CopyIcons(paths);
+}
+
+Step::Status StepCreateIcons::undo() {
+  for (auto& icon : icons_) {
     bs::error_code error;
-    bf::create_directories(icons_directory, error);
-    if (error) {
-      LOG(ERROR) << "Cannot create directory of application icons";
-      return Status::ICON_ERROR;
-    }
+    bf::remove_all(icon, error);
   }
+  return Status::OK;
+}
 
+Step::Status StepCreateIcons::CopyIcons(
+    const std::vector<bf::path>& destinations) {
   for (application_x* app :
-       GListRange<application_x*>(context_->manifest_data.get()->application)) {
+      GListRange<application_x*>(context_->manifest_data.get()->application)) {
     if (GetAppTypeForIcons() != app->type)
       continue;
-
     // TODO(t.iwanek): this is ignoring icon locale as well as other steps
     // icons should be localized
     if (app->icon) {
       icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
       bf::path source = GetIconRoot() / icon->text;
       if (bf::exists(source)) {
-        bf::path destination = icons_directory / app->appid;
-        if (source.has_extension())
-          destination += source.extension();
-        else
-          destination += ".png";
-        bs::error_code error;
-        bf::copy_file(source, destination, error);
-        if (error) {
-          LOG(ERROR) << "Cannot create package icon: " << destination;
-          return Status::ICON_ERROR;
+        for (const auto& destination : destinations) {
+          bs::error_code error;
+          if (!bf::exists(destination)) {
+            bf::create_directories(destination, error);
+            if (error) {
+              LOG(ERROR) << "Cannot create directory of application icons: "
+                  << destination;
+              return Status::ERROR;
+            }
+          }
+          bf::path destination_path = destination / app->appid;
+          if (source.has_extension())
+            destination_path += source.extension();
+          else
+            destination_path += ".png";
+          bf::copy_file(source, destination_path, error);
+          if (error) {
+            LOG(ERROR) << "Cannot create package icon: " << destination_path;
+            return Status::ICON_ERROR;
+          }
+          icons_.push_back(destination_path);
         }
-        icons_.push_back(destination);
       }
     }
   }
@@ -57,14 +70,6 @@ Step::Status StepCreateIcons::process() {
   return Status::OK;
 }
 
-Step::Status StepCreateIcons::undo() {
-  for (auto& icon : icons_) {
-    bs::error_code error;
-    bf::remove_all(icon, error);
-  }
-  return Status::OK;
-}
-
 boost::filesystem::path StepCreateIcons::GetIconRoot() const {
   // TODO(t.iwanek): shared/res is location of icons for tpk
   return context_->pkg_path.get() / "shared" / "res";
index 5be6045..f5aa0f1 100644 (file)
@@ -56,6 +56,7 @@ class StepCreateIcons : public Step {
   Status precheck() override { return Status::OK; }
 
  protected:
+  Status CopyIcons(const std::vector<boost::filesystem::path>& destinations);
   virtual boost::filesystem::path GetIconRoot() const;
   virtual std::string GetAppTypeForIcons() const;
 
index c698232..8093358 100644 (file)
@@ -51,22 +51,28 @@ Step::Status StepRecoverIcons::RecoveryUpdate() {
   return Status::OK;
 }
 
+std::vector<boost::filesystem::path> StepRecoverIcons::GetIconsPaths() {
+  std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
+  return paths;
+}
+
 bool StepRecoverIcons::TryGatherIcons() {
   if (!context_->manifest_data.get())
     return false;
   for (application_x* app :
        GListRange<application_x*>(context_->manifest_data.get()->application)) {
-    bf::path app_icon = bf::path(getIconPath(context_->uid.get()))
-      / bf::path(app->appid);
-    if (app->icon) {
-      icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
-      app_icon += bf::path(icon->text).extension();
-    } else {
-      app_icon += ".png";
+    for (const auto& path : GetIconsPaths()) {
+      bf::path icon_path = path / bf::path(app->appid);
+      if (app->icon) {
+        icon_x* icon = reinterpret_cast<icon_x*>(app->icon->data);
+        icon_path += bf::path(icon->text).extension();
+      } else {
+        icon_path += ".png";
+      }
+      bf::path icon_backup = GetBackupPathForIconFile(icon_path);
+      if (bf::exists(icon_backup) || bf::exists(icon_path))
+          icons_.emplace_back(icon_path, icon_backup);
     }
-    bf::path icon_backup = GetBackupPathForIconFile(app_icon);
-    if (bf::exists(icon_backup) || bf::exists(app_icon))
-        icons_.emplace_back(app_icon, icon_backup);
   }
   return true;
 }
index ce41987..337c9d6 100644 (file)
@@ -33,6 +33,9 @@ class StepRecoverIcons : public recovery::StepRecovery {
   Status RecoveryNew() override;
   Status RecoveryUpdate() override;
 
+ protected:
+  virtual std::vector<boost::filesystem::path> GetIconsPaths();
+
  private:
   bool TryGatherIcons();