Fix getting icon path 31/55731/5
authorSangyoon Jang <s89.jang@samsung.com>
Tue, 29 Dec 2015 04:47:47 +0000 (13:47 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Wed, 13 Jan 2016 01:41:52 +0000 (10:41 +0900)
- get icon path from tpk package also
- check if the file exists from unpacked dir
- check from shared directory first

Change-Id: Ifd30f1f28d52bc1344b8a9ed7800612ac0960a60
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/tpk/step/step_parse.cc

index 57083a0..28efb9f 100644 (file)
@@ -84,20 +84,17 @@ bf::path StepParse::FindIcon(const std::string& filename) {
   if (filename.length() == 0)
     return icon_path;
 
-  // icon path of tpk app will be modified later
-  if (context_->pkg_type.get().compare("rpm") != 0)
-    return filename;
-
   if (index(filename.c_str(), '/'))
     return filename;
 
+  // FIXME: icons for preloaded apps should also be moved to "shared/res"
   icon_path = bf::path(getIconPath(context_->uid.get())) / filename;
   if (access(icon_path.c_str(), F_OK) == 0)
     return icon_path;
 
   icon_path = bf::path(getIconPath(context_->uid.get()) /
               bf::path("default/small") / filename);
-  if (access(icon_path.c_str(), F_OK) == 0)
+  if (bf::exists(icon_path))
     return icon_path;
 
   if (context_->uid.get() == GLOBAL_USER) {
@@ -108,17 +105,27 @@ bf::path StepParse::FindIcon(const std::string& filename) {
     tzplatform_reset_user();
   }
 
-  icon_path = app_path / context_->pkgid.get() / filename;
-  if (access(icon_path.c_str(), F_OK) == 0)
+  icon_path =
+      context_->unpacked_dir_path.get() / bf::path("shared/res") / filename;
+  if (bf::exists(icon_path)) {
+    icon_path =
+        app_path / context_->pkgid.get() / bf::path("shared/res") / filename;
     return icon_path;
+  }
 
-  icon_path = app_path / context_->pkgid.get() / bf::path("res/icons") / filename;
-  if (access(icon_path.c_str(), F_OK) == 0)
+  icon_path =
+      context_->unpacked_dir_path.get() / bf::path("res/icons") / filename;
+  if (bf::exists(icon_path)) {
+    icon_path =
+        app_path / context_->pkgid.get() / bf::path("res/icons") / filename;
     return icon_path;
+  }
 
-  icon_path = app_path / context_->pkgid.get() / bf::path("shared/res") / filename;
-  if (access(icon_path.c_str(), F_OK) == 0)
+  icon_path = context_->unpacked_dir_path.get() / filename;
+  if (bf::exists(icon_path)) {
+    icon_path = app_path / context_->pkgid.get() / filename;
     return icon_path;
+  }
 
   icon_path = "";
   return icon_path;
@@ -669,6 +676,14 @@ common_installer::Step::Status StepParse::process() {
     return common_installer::Step::Status::PARSE_ERROR;
   }
 
+  // Copy data from ManifestData to InstallerContext
+  std::shared_ptr<const PackageInfo> info =
+      std::static_pointer_cast<const PackageInfo>(
+          parser_->GetManifestData(
+              app_keys::kManifestKey));
+
+  context_->pkgid.set(info->package());
+
   manifest_x* manifest =
       static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
 
@@ -681,14 +696,6 @@ common_installer::Step::Status StepParse::process() {
   if (!context_->tep_path.get().empty())
     manifest->tep_name = context_->tep_path.get().c_str();
 
-  // Copy data from ManifestData to InstallerContext
-  std::shared_ptr<const PackageInfo> info =
-      std::static_pointer_cast<const PackageInfo>(
-          parser_->GetManifestData(
-              app_keys::kManifestKey));
-
-  context_->pkgid.set(manifest->package);
-
   // write pkgid for recovery file
   if (context_->recovery_info.get().recovery_file) {
     context_->recovery_info.get().recovery_file->set_pkgid(manifest->package);