Fix static analysis issue 27/240727/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 3 Aug 2020 07:40:27 +0000 (16:40 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 11 Aug 2020 03:35:32 +0000 (12:35 +0900)
Fix uncaught exception.

Change-Id: Ib2526443fcc27fd615fb9325282dbfd3515e9844
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
(cherry picked from commit 140ba528998c7fa6f607bb081bca66a1e9518034)

src/common/utils/file_util.cc
src/pkg_recovery/pkg_recovery.cc

index 6595256..e5f602f 100644 (file)
@@ -339,12 +339,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 72babe0..9e9ad0a 100644 (file)
@@ -80,10 +80,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;
@@ -94,11 +95,10 @@ void PkgRecoveryService::SearchBackupFiles(uid_t uid) {
         else
           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();
   }
 }