Remove boost dependency
[platform/core/appfw/app-installers.git] / src / pkg_recovery / pkg_recovery.cc
index 266748c..fb18627 100644 (file)
@@ -2,10 +2,6 @@
 // Use of this source code is governed by an apache-2.0 license that can be
 // found in the LICENSE file.
 
-#include <boost/exception/diagnostic_information.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-
 #include <glib.h>
 #include <common/utils/file_util.h>
 #include <common/utils/request.h>
 #include <tzplatform_config.h>
 
 #include <array>
+#include <exception>
+#include <filesystem>
 #include <regex>
 #include <string>
 #include <vector>
 
-namespace bf = boost::filesystem;
 namespace ci = common_installer;
+namespace fs = std::filesystem;
 
 namespace {
 
@@ -55,7 +53,7 @@ std::vector<std::string> ParseRecoveryFile(const char* file) {
       break;
     }
 
-    if (!boost::filesystem::exists(line_data))
+    if (!std::filesystem::exists(line_data))
       continue;
 
     arguments.emplace_back(line_data);
@@ -92,7 +90,7 @@ bool PkgRecoveryService::RunBackend(uid_t uid, const char* type,
   if (std::string(type) == "unified") {
     auto arguments = ParseRecoveryFile(file);
     if (!arguments.size())
-      return ci::Remove(bf::path(file));
+      return ci::Remove(fs::path(file));
 
     arguments.emplace(arguments.begin(), "-b");
     arguments.emplace_back("-u");
@@ -106,7 +104,7 @@ bool PkgRecoveryService::RunBackend(uid_t uid, const char* type,
   if (WIFSIGNALED(status) || WEXITSTATUS(status))
     return false;
 
-  ci::Remove(bf::path(file));
+  ci::Remove(fs::path(file));
 
   return true;
 }
@@ -130,33 +128,33 @@ void PkgRecoveryService::Run() {
 }
 
 void PkgRecoveryService::SearchBackupFiles(uid_t uid) {
-  const bf::path recovery_dir = ci::GetRootAppPath(false, uid);
+  const fs::path recovery_dir = ci::GetRootAppPath(false, uid);
   try {
-    for (bf::directory_iterator iter(recovery_dir);
-        iter != bf::directory_iterator();
+    for (fs::directory_iterator iter(recovery_dir);
+        iter != fs::directory_iterator();
         ++iter) {
       std::string file = iter->path().filename().string();
       std::regex backup_regex(kBackupFilePattern);
       std::smatch match;
       if (std::regex_search(file, match, backup_regex)) {
-        bf::path orig_file(iter->path().parent_path() / iter->path().stem());
-        if (bf::exists(orig_file))
-          bf::remove(orig_file);
-        bf::rename(iter->path(), orig_file);
+        fs::path orig_file(iter->path().parent_path() / iter->path().stem());
+        if (fs::exists(orig_file))
+          fs::remove(orig_file);
+        fs::rename(iter->path(), orig_file);
       }
     }
-  } catch (...) {
+  } catch (const std::exception& e) {
     LOG(WARNING) << "Exception occurred: "
-                 << boost::current_exception_diagnostic_information();
+        << typeid(e).name() << ", " << e.what();
   }
 }
 
 std::vector<RecoverEntry> PkgRecoveryService::SearchRecoveryFiles(uid_t uid) {
   std::vector<RecoverEntry> list;
-  const bf::path recovery_dir = ci::GetRootAppPath(false, uid);
+  const fs::path recovery_dir = ci::GetRootAppPath(false, uid);
   LOG(INFO) << "RootAppPath: " << recovery_dir;
-  for (bf::directory_iterator iter(recovery_dir);
-      iter != bf::directory_iterator();
+  for (fs::directory_iterator iter(recovery_dir);
+      iter != fs::directory_iterator();
       ++iter) {
     try {
       std::string file = iter->path().filename().string();
@@ -170,9 +168,9 @@ std::vector<RecoverEntry> PkgRecoveryService::SearchRecoveryFiles(uid_t uid) {
         else
           list.emplace_back(type, iter->path().string());
       }
-    } catch (...) {
+    } catch (const std::exception& e) {
       LOG(WARNING) << "Exception occurred: "
-                   << boost::current_exception_diagnostic_information();
+          << typeid(e).name() << ", " << e.what();
       continue;
     }
   }
@@ -186,7 +184,7 @@ void PkgRecoveryService::ProcessRecovery(uid_t uid,
   for (const auto& entry : entries) {
     const char* type = entry.first.c_str();
     const char* file = entry.second.c_str();
-    if (!bf::exists(file))
+    if (!fs::exists(file))
       continue;
 
     if (!RunBackend(uid, type, file))