Fix icon copying 57/57257/6 accepted/tizen/mobile/20160122.032611 accepted/tizen/tv/20160122.032659 accepted/tizen/wearable/20160122.032711 submit/tizen/20160120.112210
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 18 Jan 2016 09:57:25 +0000 (10:57 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 20 Jan 2016 08:41:05 +0000 (09:41 +0100)
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: I61f30b4306ae31d8e88f08f3a2f7ed646d28ead7

src/common/backup_paths.cc
src/common/backup_paths.h
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
src/common/step/step_remove_icons.cc

index b82bcc4..d4495db 100644 (file)
@@ -34,4 +34,8 @@ boost::filesystem::path GetBackupPathForIconFile(
   return GetBackupPath(icon_path);
 }
 
+std::string GetIconFileBackupExtension() {
+  return ".bck";
+}
+
 }  // namespace common_installer
index c8ec148..cc5fe15 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <boost/filesystem/path.hpp>
 
+#include <string>
+
 namespace common_installer {
 
 /**
@@ -42,6 +44,12 @@ boost::filesystem::path GetBackupPathForManifestFile(
 boost::filesystem::path GetBackupPathForIconFile(
     const boost::filesystem::path& icon_path);
 
+/**
+ * @brief GetIconFileBackupExtension
+ * @return extension for backup icon files
+ */
+std::string GetIconFileBackupExtension();
+
 }  // namespace common_installer
 
 #endif  // COMMON_BACKUP_PATHS_H_
index 717ff0a..5a7cddc 100644 (file)
@@ -9,6 +9,8 @@
 #include <boost/filesystem.hpp>
 #include <boost/system/error_code.hpp>
 
+#include <string>
+
 #include "common/backup_paths.h"
 #include "common/utils/file_util.h"
 #include "common/utils/glist_range.h"
@@ -20,48 +22,20 @@ 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)) {
-    for (const auto& source : sources) {
-      bf::path source_path = source / bf::path(app->appid);
+  for (auto iter = bf::directory_iterator(getIconPath(context_->uid.get()));
+      iter != bf::directory_iterator(); ++iter) {
+    if (!bf::is_regular_file(iter->path()))
+      continue;
+    for (application_x* app : GListRange<application_x*>(
+        context_->old_manifest_data.get()->application)) {
       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;
+        std::string filename = iter->path().filename().string();
+        if (filename.find(app->appid) == 0) {
+          bf::path icon_backup = GetBackupPathForIconFile(iter->path());
+          icons_.emplace_back(iter->path(), icon_backup);
         }
-        source_path += bf::path(icon->text).extension();
-      } else {
-        source_path += ".png";
       }
-      bf::path icon_backup = GetBackupPathForIconFile(source_path);
-      if (bf::exists(source_path))
-          icons_.emplace_back(source_path, icon_backup);
     }
   }
 
@@ -77,6 +51,23 @@ Step::Status StepBackupIcons::MoveIcons(
   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 6096c4d..49de070 100644 (file)
@@ -52,9 +52,6 @@ class StepBackupIcons : public Step {
    */
   Status precheck() override { return Status::OK; }
 
- protected:
-  Status MoveIcons(const std::vector<boost::filesystem::path>& sources);
-
  private:
   void RemoveBackupIcons();
 
index 1e77c2f..edf3fb9 100644 (file)
@@ -16,11 +16,6 @@ namespace bs = boost::system;
 namespace common_installer {
 namespace filesystem {
 
-Step::Status StepCreateIcons::process() {
-  std::vector<bf::path> paths { getIconPath(context_->uid.get()) };
-  return CopyIcons(paths);
-}
-
 Step::Status StepCreateIcons::undo() {
   for (auto& icon : icons_) {
     bs::error_code error;
@@ -29,40 +24,38 @@ Step::Status StepCreateIcons::undo() {
   return Status::OK;
 }
 
-Step::Status StepCreateIcons::CopyIcons(
-    const std::vector<bf::path>& destinations) {
+Step::Status StepCreateIcons::process() {
+  bf::path destination = getIconPath(context_->uid.get());
+  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;
+    }
+  }
+
   for (application_x* app :
       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
+    // TODO(t.iwanek): this ignores icon locale as well in same way 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;
+      bf::path source(icon->text);
       if (bf::exists(source)) {
-        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);
+        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
+                     << " , error: " << error;
+          return Status::ICON_ERROR;
         }
+        icons_.push_back(destination_path);
       }
     }
   }
@@ -70,14 +63,5 @@ Step::Status StepCreateIcons::CopyIcons(
   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";
-}
-
-std::string StepCreateIcons::GetAppTypeForIcons() const {
-  return "capp";
-}
-
 }  // namespace filesystem
 }  // namespace common_installer
index f5aa0f1..7d25971 100644 (file)
@@ -55,11 +55,6 @@ 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;
-
  private:
   std::vector<boost::filesystem::path> icons_;
 
index 8093358..eb9e187 100644 (file)
@@ -51,27 +51,33 @@ 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)) {
-    for (const auto& path : GetIconsPaths()) {
-      bf::path icon_path = path / bf::path(app->appid);
+
+  // gather icon info
+  for (auto iter = bf::directory_iterator(getIconPath(context_->uid.get()));
+      iter != bf::directory_iterator(); ++iter) {
+    if (!bf::is_regular_file(iter->path()))
+      continue;
+    for (application_x* app : GListRange<application_x*>(
+        context_->manifest_data.get()->application)) {
       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 p = iter->path();
+        std::string filename = iter->path().filename().string();
+        if (filename.find(app->appid) == 0) {
+          bf::path icon;
+          bf::path icon_backup;
+          if (p.extension() == GetIconFileBackupExtension()) {
+            icon_backup = p;
+            icon = p.replace_extension("");
+          } else {
+            icon = p;
+            icon_backup = GetBackupPathForIconFile(iter->path());
+          }
+          icons_.insert(std::make_pair(icon, icon_backup));
+        }
       }
-      bf::path icon_backup = GetBackupPathForIconFile(icon_path);
-      if (bf::exists(icon_backup) || bf::exists(icon_path))
-          icons_.emplace_back(icon_path, icon_backup);
     }
   }
   return true;
index 337c9d6..4f63973 100644 (file)
@@ -9,8 +9,9 @@
 
 #include <manifest_parser/utils/logging.h>
 
+#include <set>
+#include <string>
 #include <utility>
-#include <vector>
 
 #include "common/installer_context.h"
 #include "common/step/step_recovery.h"
@@ -33,13 +34,10 @@ class StepRecoverIcons : public recovery::StepRecovery {
   Status RecoveryNew() override;
   Status RecoveryUpdate() override;
 
- protected:
-  virtual std::vector<boost::filesystem::path> GetIconsPaths();
-
  private:
   bool TryGatherIcons();
 
-  std::vector<std::pair<boost::filesystem::path, boost::filesystem::path>>
+  std::set<std::pair<boost::filesystem::path, boost::filesystem::path>>
       icons_;
 
   SCOPE_LOG_TAG(RecoverIcons)
index 5ad142e..de3304b 100644 (file)
@@ -8,6 +8,7 @@
 #include <pkgmgr-info.h>
 
 #include <cstring>
+#include <string>
 
 #include "common/backup_paths.h"
 #include "common/utils/file_util.h"
@@ -29,23 +30,20 @@ Step::Status StepRemoveIcons::precheck() {
 }
 
 Step::Status StepRemoveIcons::process() {
-  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";
-    }
-    if (bf::exists(app_icon)) {
-      bf::path backup_icon_file = GetBackupPathForIconFile(app_icon);
-      if (!MoveFile(app_icon, backup_icon_file)) {
-        LOG(ERROR) << "Failed to create backup for icon: " << app_icon;
-        return Status::ICON_ERROR;
+  for (auto iter = bf::directory_iterator(getIconPath(context_->uid.get()));
+      iter != bf::directory_iterator(); ++iter) {
+    if (!bf::is_regular_file(iter->path()))
+      continue;
+    for (application_x* app :
+        GListRange<application_x*>(
+           context_->manifest_data.get()->application)) {
+      if (app->icon) {
+        std::string filename = iter->path().filename().string();
+        if (filename.find(app->appid) == 0) {
+          bf::path icon_backup = GetBackupPathForIconFile(iter->path());
+          backups_.emplace_back(iter->path(), icon_backup);
+        }
       }
-      backups_.emplace_back(backup_icon_file, app_icon);
     }
   }
   return Status::OK;