Fix static analysis issue
[platform/core/appfw/app-installers.git] / src / pkg_recovery / pkg_recovery.cc
index a2a187b..266748c 100644 (file)
@@ -7,14 +7,15 @@
 #include <boost/filesystem/path.hpp>
 
 #include <glib.h>
-#include <common/request.h>
 #include <common/utils/file_util.h>
+#include <common/utils/request.h>
 #include <common/utils/subprocess.h>
 #include <common/utils/user_util.h>
 #include <manifest_parser/utils/logging.h>
 #include <sys/types.h>
 #include <tzplatform_config.h>
 
+#include <array>
 #include <regex>
 #include <string>
 #include <vector>
@@ -119,7 +120,7 @@ void PkgRecoveryService::Run() {
 
   // recover normal user packages
   ci::UserList list = ci::GetUserList();
-  for (auto userinfo : list) {
+  for (const auto& userinfo : list) {
     uid_t uid = std::get<0>(userinfo);
     LOG(INFO) << "Searching recovery files for user " << std::get<0>(userinfo);
     SearchBackupFiles(uid);
@@ -130,10 +131,10 @@ 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();
   }
 }
 
@@ -183,7 +183,7 @@ std::vector<RecoverEntry> PkgRecoveryService::SearchRecoveryFiles(uid_t uid) {
 void PkgRecoveryService::ProcessRecovery(uid_t uid,
     const std::vector<RecoverEntry>& entries) {
   LOG(INFO) << "Process recovery for user " << uid;
-  for (auto entry : entries) {
+  for (const auto& entry : entries) {
     const char* type = entry.first.c_str();
     const char* file = entry.second.c_str();
     if (!bf::exists(file))
@@ -197,7 +197,12 @@ void PkgRecoveryService::ProcessRecovery(uid_t uid,
 }  // namespace
 
 int main() {
-  PkgRecoveryService service;
-  service.Run();
-  return 0;
+  try {
+    PkgRecoveryService service;
+    service.Run();
+    return 0;
+  } catch(...) {
+    LOG(ERROR) << "Exception occured";
+    return -1;
+  }
 }