Fix StepTpkPatchIcons 50/210950/5
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 26 Jul 2019 07:25:20 +0000 (16:25 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 5 Sep 2019 10:13:29 +0000 (10:13 +0000)
- Fix coding rules.
- Fix possible static issue.
- Add error checking routines.

Change-Id: Ic7d8e7a3977a196c872cb55f8ec68116aeeb82ba
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/tpk/step/filesystem/step_tpk_patch_icons.cc

index 74d8f20..ed15124 100644 (file)
@@ -36,10 +36,10 @@ bf::path LocateIcon(const bf::path& filename, const std::string& pkgid,
   locations.push_back(res_icons_location);
 
   for (auto& location : locations) {
-    if (bf::exists(location)) {
+    if (bf::exists(location))
       return location;
-    }
   }
+
   return {};
 }
 
@@ -56,16 +56,19 @@ common_installer::Step::Status StepTpkPatchIcons::ProcessIconOutsidePackage(
     const bf::path& common_icon_location, const bf::path& icon_text,
     application_x* app, icon_x* icon) {
   bf::path destination = common_icon_location / app->appid;
-  if (!icon_text.extension().empty()) {
+  if (!icon_text.extension().empty())
     destination += icon_text.extension();
-  } else {
+  else
     destination += ".png";
-  }
-  if (!common_installer::CopyFile(icon_text, destination)) {
+
+  if (!common_installer::CopyFile(icon_text, destination))
     return Status::ICON_ERROR;
-  }
+
   free(const_cast<char*>(icon->text));
   icon->text = strdup(destination.c_str());
+  if (!icon->text)
+    return Status::ICON_ERROR;
+
   return Status::OK;
 }
 
@@ -78,17 +81,23 @@ common_installer::Step::Status StepTpkPatchIcons::FixIconLocation(
                                context_->is_readonly_package.get());
   if (!source.empty()) {
     LOG(DEBUG) << "Fix location of icon: " << source << " to: " << icon_text;
-    if (!common_installer::CopyFile(source, icon_text)) {
+    if (!common_installer::CopyFile(source, icon_text))
       return Status::ICON_ERROR;
-    }
   }
   return Status::OK;
 }
 
 common_installer::Step::Status StepTpkPatchIcons::process() {
   bf::path common_icon_location = context_->GetPkgPath() / "shared" / "res";
+
   bs::error_code error;
   bf::create_directories(common_icon_location, error);
+  if (error) {
+      LOG(ERROR) << "Failed to create directory :" << common_icon_location
+                 << ", error :"  << error.message();
+      return Status::ICON_ERROR;
+  }
+
   for (application_x* app :
       GListRange<application_x*>(context_->manifest_data.get()->application)) {
     if (!IsTpkApp(app))
@@ -123,7 +132,7 @@ common_installer::Step::Status StepTpkPatchIcons::process() {
         }
       } else {
         // look for icon in different location if it doesn't exist
-        if (!bf::exists(icon->text)) {
+        if (!bf::exists(icon_text)) {
           Status status = FixIconLocation(icon_text);
           if (status != Status::OK)
             return status;