Fix static analysis issue 90/240090/4
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 3 Aug 2020 07:40:27 +0000 (16:40 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 3 Aug 2020 08:28:14 +0000 (17:28 +0900)
Fix uncaught exception.

Change-Id: Ib2526443fcc27fd615fb9325282dbfd3515e9844
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/global_recovery_file.cc
src/common/utils/file_util.cc
src/pkg_recovery/pkg_recovery.cc

index ae6da34..5af5850 100644 (file)
@@ -14,6 +14,7 @@
 #include "common/pkgmgr_interface.h"
 
 namespace bf = boost::filesystem;
+namespace bs = boost::system;
 namespace ci = common_installer;
 
 namespace {
@@ -42,9 +43,10 @@ GlobalRecoveryFile::GlobalRecoveryFile(
 }
 
 GlobalRecoveryFile::~GlobalRecoveryFile() {
-  if (bf::exists(recovery_filepath_))
+  bs::error_code ec;
+  if (bf::exists(recovery_filepath_, ec))
     ci::Remove(recovery_filepath_);
-  if (bf::exists(backup_path_))
+  if (bf::exists(backup_path_, ec))
     ci::Remove(backup_path_);
 }
 
index b093532..671deb8 100644 (file)
@@ -331,12 +331,18 @@ bool RemoveAll(const bf::path& path) {
 }
 
 bool Remove(const bf::path& path) {
-  if (!exists(path) && !bf::is_symlink(bf::symlink_status(path)))
+  bs::error_code error;
+  if (!exists(path, error)) {
+    if (error) {
+      LOG(ERROR) << "Cannot remove: " << path << ", " << error.message();
+      return false;
+    }
+    return true;
+  }
+  if (!bf::is_symlink(bf::symlink_status(path)))
     return true;
 
-  bs::error_code error;
   bf::remove(path, error);
-
   if (error) {
     LOG(ERROR) << "Cannot remove: " << path << ", " << error.message();
     return false;
index 4a908d6..52c6faa 100644 (file)
@@ -130,10 +130,11 @@ void PkgRecoveryService::Run() {
 
 void PkgRecoveryService::SearchBackupFiles(uid_t uid) {
   const bf::path recovery_dir = ci::GetRootAppPath(false, uid);
-  for (bf::directory_iterator iter(recovery_dir);
-      iter != bf::directory_iterator();
-      ++iter) {
-    try {
+  try {
+    for (bf::directory_iterator iter(recovery_dir);
+        iter != bf::directory_iterator();
+        ++iter) {
+
       std::string file = iter->path().filename().string();
       std::regex backup_regex(kBackupFilePattern);
       std::smatch match;
@@ -143,11 +144,10 @@ void PkgRecoveryService::SearchBackupFiles(uid_t uid) {
           bf::remove(orig_file);
         bf::rename(iter->path(), orig_file);
       }
-    } catch (...) {
-      LOG(WARNING) << "Exception occurred: "
-                   << boost::current_exception_diagnostic_information();
-      continue;
     }
+  } catch (...) {
+    LOG(WARNING) << "Exception occurred: "
+                 << boost::current_exception_diagnostic_information();
   }
 }