Continue recovery process when exception occured instead of exit 08/131008/6
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 25 May 2017 04:51:03 +0000 (13:51 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 26 May 2017 09:20:42 +0000 (18:20 +0900)
Change-Id: Id45e31e2c8d252db09314d4eb898ae7b968bacb2
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/pkg_recovery/pkg_recovery_helper.cc

index 775f8af..ea333a8 100644 (file)
@@ -89,15 +89,21 @@ std::vector<RecoverEntry> SearchRecoveryFiles(uid_t uid) {
   for (bf::directory_iterator iter(recovery_dir);
       iter != bf::directory_iterator();
       ++iter) {
-    if (bf::is_directory(iter->path()))
+    try {
+      if (bf::is_directory(iter->path()))
+        continue;
+      std::string file = iter->path().filename().string();
+      std::regex recovery_regex(kRecoveryFilePattern);
+      std::smatch match;
+      if (std::regex_search(file, match, recovery_regex)) {
+        LOG(INFO) << "Found recovery file: " << file;
+        std::string type(match[1]);
+        list.emplace_back(type, iter->path().string());
+      }
+    } catch (...) {
+      LOG(WARNING) << "Exception occurred: "
+                   << boost::current_exception_diagnostic_information();
       continue;
-    std::string file = iter->path().filename().string();
-    std::regex recovery_regex(kRecoveryFilePattern);
-    std::smatch match;
-    if (std::regex_search(file, match, recovery_regex)) {
-      LOG(INFO) << "Found recovery file: " << file;
-      std::string type(match[1]);
-      list.emplace_back(type, iter->path().string());
     }
   }
 
@@ -109,26 +115,20 @@ std::vector<RecoverEntry> SearchRecoveryFiles(uid_t uid) {
 int main() {
   uid_t uid = getuid();
   std::vector<std::pair<std::string, std::string>> list;
-  try {
-    list = SearchRecoveryFiles(uid);
+  list = SearchRecoveryFiles(uid);
+  for (auto entry : list) {
+    if (!RequestRecoveryService(uid, entry.first.c_str(),
+        entry.second.c_str()))
+      LOG(ERROR) << "Failed to recover installation: " << entry.second;
+  }
+
+  if (ci::IsAdminUser(uid)) {
+    list = SearchRecoveryFiles(kGlobalUserUid);
     for (auto entry : list) {
       if (!RequestRecoveryService(uid, entry.first.c_str(),
           entry.second.c_str()))
         LOG(ERROR) << "Failed to recover installation: " << entry.second;
     }
-
-    if (ci::IsAdminUser(uid)) {
-      list = SearchRecoveryFiles(kGlobalUserUid);
-      for (auto entry : list) {
-        if (!RequestRecoveryService(uid, entry.first.c_str(),
-          entry.second.c_str()))
-          LOG(ERROR) << "Failed to recover installation: " << entry.second;
-      }
-    }
-  } catch (...) {
-    std::cerr << "Exception occurred: "
-              << boost::current_exception_diagnostic_information() << std::endl;
-    return -1;
   }
   return 0;
 }