Add some missing error checking 18/114618/5
authorBartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
Tue, 14 Feb 2017 08:05:22 +0000 (09:05 +0100)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Tue, 7 Mar 2017 13:12:01 +0000 (05:12 -0800)
Requires:
 - https://review.tizen.org/gerrit/#/c/114612/

Change-Id: Ia78c272c9f3a2ec8f69993bf6ac2484e28855fb1

src/lib/tpk_archive_info.cc
src/tpk/step/filesystem/step_tpk_update_package_directory.cc
src/tpk/step/pkgmgr/step_convert_xml.cc
src/tpk/tpk_app_query_interface.cc

index 8aebcbd3af10a670707727ce955966f1a48ab571..a010f58ad3b118146a81d6fd8ba5ae26a751be77 100644 (file)
@@ -291,7 +291,7 @@ bool TpkArchiveInfo::GetArchiveInfo(const char* file_path,
 
   if (!GetPackageInfo(parser, info)) {
     LOG(ERROR) << "Failed to get package info";
-    bf::remove_all(tmp_dir);
+    ci::RemoveAll(tmp_dir);
     return false;
   }
   if (!GetAuthorInfo(parser, info))
@@ -310,18 +310,18 @@ bool TpkArchiveInfo::GetArchiveInfo(const char* file_path,
     bf::path icon_path = bf::path(kSharedResDir) / icon;
     if (!ExtractPackageArchive(
         file_path, icon_path.string().c_str(), tmp_dir)) {
-      bf::remove_all(tmp_dir);
+      ci::RemoveAll(tmp_dir);
       return false;
     }
     if (!ReadIcon(icon_path, tmp_dir, info)) {
       LOG(WARNING) << "Failed to get icon info";
-      bf::remove_all(tmp_dir);
+      ci::RemoveAll(tmp_dir);
       return false;
     }
   }
 
   free(locale);
-  bf::remove_all(tmp_dir);
+  ci::RemoveAll(tmp_dir);
 
   return true;
 }
index 03ca4f8f8f515fb181b753141a1fc7184cb5e781..601828c2ba4e658fabe63e7567d28f6c4c87f079 100644 (file)
@@ -76,14 +76,8 @@ ci::Step::Status StepTpkUpdatePackageDirectory::RestoreDirectory(
 
 ci::Step::Status StepTpkUpdatePackageDirectory::RemoveDirectory(
     const boost::filesystem::path& dir_path) {
-  if (bf::exists(dir_path)) {
-    bs::error_code error;
-    bf::remove_all(dir_path, error);
-    if (error) {
-      LOG(ERROR) << "Failed to remove directory: " << dir_path;
-      return Status::APP_DIR_ERROR;
-    }
-  }
+  if (!ci::RemoveAll(dir_path))
+    return Status::APP_DIR_ERROR;
   return Status::OK;
 }
 
index 6fedec9cfd2d0488995058f1d48ac16755d85f7a..a2f3bea4529fcf7cfa5b53e6c0f165e9cb6faf8b 100644 (file)
 
 #include <string>
 
+#include "common/utils/file_util.h"
 
 namespace bs = boost::system;
 namespace bf = boost::filesystem;
+namespace ci = common_installer;
 
 namespace {
 
@@ -139,12 +141,8 @@ common_installer::Step::Status StepConvertXml::clean() {
 
 common_installer::Step::Status StepConvertXml::undo() {
   if (!backup_path_.empty()) {
-    bs::error_code error;
-    bf::remove(new_path_, error);
-    if (error) {
-      LOG(WARNING) << "Failed to remove " << new_path_
-                   << " due to error " << error;
-    } else {
+    if (Remove(new_path_) {
+      bs::error_code error;
       bf::rename(backup_path_, new_path_, error);
       if (error)
         LOG(WARNING) << "Failed to restore " << new_path_
index f74e7ae7c658803daf6e7419a4206c0e2c7d8cca..49adc0f4528f7fb8b215f7d4247ea90602cf3d0a 100644 (file)
@@ -41,12 +41,12 @@ std::string GetPkgIdFromPath(const std::string& path) {
     return {};
   if (!common_installer::ExtractToTmpDir(path.c_str(), tmp_path,
       kManifestFileName)) {
-    bf::remove_all(tmp_path, code);
+    ci::RemoveAll(tmp_path);
     return {};
   }
   bf::path manifest_path = tmp_path / kManifestFileName;
   if (!bf::exists(manifest_path)) {
-    bf::remove_all(tmp_path, code);
+    ci::RemoveAll(tmp_path);
     return {};
   }
 
@@ -58,7 +58,7 @@ std::string GetPkgIdFromPath(const std::string& path) {
   if (!package_info)
     return {};
   std::string pkg_id = package_info->package();
-  bf::remove_all(tmp_path, code);
+  ci::RemoveAll(tmp_path);
   return pkg_id;
 }