Fix crash issue of pkg_recovery_helper 32/122932/2
authorSangyoon Jang <s89.jang@samsung.com>
Tue, 4 Apr 2017 04:17:04 +0000 (13:17 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Wed, 5 Apr 2017 11:56:35 +0000 (04:56 -0700)
Change-Id: I719b270557fd5bc1dd801348ef33a554f4702258
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
src/pkg_recovery/pkg_recovery_helper.cc

index cd7e513..50875e9 100644 (file)
@@ -21,6 +21,8 @@
 #include <regex>
 #include <string>
 #include <iostream>
+#include <utility>
+#include <vector>
 
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
@@ -28,6 +30,8 @@ namespace ci = common_installer;
 
 namespace {
 
+typedef std::pair<std::string, std::string> RecoverEntry;
+
 const char kRecoveryFilePattern[] = "^(.*)-recovery-(.*)";
 const char kRecoveryMethodName[] = "RecoverPkg";
 const char kDBusServiceName[] = "org.tizen.pkg_recovery";
@@ -80,8 +84,9 @@ bool RequestRecoveryService(uid_t uid, const char* type, const char* file) {
   return result;
 }
 
-bool DoRecoveryProcess(uid_t uid) {
-  bf::path recovery_dir = ci::GetRootAppPath(false, uid);
+std::vector<RecoverEntry> SearchRecoveryFiles(uid_t uid) {
+  std::vector<RecoverEntry> list;
+  const bf::path recovery_dir = ci::GetRootAppPath(false, uid);
   for (bf::directory_iterator iter(recovery_dir);
       iter != bf::directory_iterator();
       ++iter) {
@@ -93,22 +98,34 @@ bool DoRecoveryProcess(uid_t uid) {
     if (std::regex_search(file, match, recovery_regex)) {
       LOG(INFO) << "Found recovery file: " << file;
       std::string type(match[1]);
-      if (!RequestRecoveryService(uid, type.c_str(), iter->path().c_str()))
-        LOG(ERROR) << "Failed to recover installation: " << file;
+      list.emplace_back(type, iter->path().string());
     }
   }
 
-  return true;
+  return list;
 }
 
 }  // namespace
 
 int main() {
   uid_t uid = getuid();
+  std::vector<std::pair<std::string, std::string>> list;
   try {
-    DoRecoveryProcess(uid);
-    if (ci::IsAdminUser(uid))
-      DoRecoveryProcess(kGlobalUserUid);
+    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;
+      }
+    }
   } catch (const bf::filesystem_error& e) {
     LOG(ERROR) << "Exception occurred: " << e.what();
     return -1;