Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / global_recovery_file.cc
index d6a6fe1..f4f57fd 100644 (file)
@@ -4,27 +4,27 @@
 
 #include "common/global_recovery_file.h"
 
-#include <boost/filesystem/path.hpp>
-
 #include <manifest_parser/utils/logging.h>
+#include <unistd.h>
 
 #include <algorithm>
+#include <filesystem>
 #include <string>
+#include <system_error>
 #include <vector>
 
 #include "common/utils/file_util.h"
 #include "common/pkgmgr_interface.h"
 
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
 namespace ci = common_installer;
+namespace fs = std::filesystem;
 
 namespace {
 
 const char kGlobalTypeName[] = "unified";
 
-bf::path Backup(const bf::path& filepath) {
-  bf::path backup_path(filepath);
+fs::path Backup(const fs::path& filepath) {
+  fs::path backup_path(filepath);
   backup_path += ".bck";
 
   if (!ci::MoveFile(filepath, backup_path) ||
@@ -45,16 +45,16 @@ GlobalRecoveryFile::GlobalRecoveryFile(
 }
 
 GlobalRecoveryFile::~GlobalRecoveryFile() {
-  bs::error_code ec;
-  if (bf::exists(recovery_filepath_, ec))
+  std::error_code ec;
+  if (fs::exists(recovery_filepath_, ec))
     ci::Remove(recovery_filepath_);
-  if (bf::exists(backup_path_, ec))
+  if (fs::exists(backup_path_, ec))
     ci::Remove(backup_path_);
 }
 
 
 bool GlobalRecoveryFile::Init() {
-  boost::filesystem::path root_path = ci::GetRootAppPath(
+  std::filesystem::path root_path = ci::GetRootAppPath(
         pkgmgr_->GetIsPreloadRequest(), pkgmgr_->GetUid());
   recovery_filepath_ = GenerateRecoveryFilePath(root_path, kGlobalTypeName);
   if (recovery_filepath_.empty())
@@ -65,9 +65,9 @@ bool GlobalRecoveryFile::Init() {
 
 std::string GlobalRecoveryFile::AddPathWithType(
     const std::string& pkg_type) {
-  boost::filesystem::path root_path = ci::GetRootAppPath(
+  std::filesystem::path root_path = ci::GetRootAppPath(
           pkgmgr_->GetIsPreloadRequest(), pkgmgr_->GetUid());
-  bf::path recovery_filepath = GenerateRecoveryFilePath(root_path, pkg_type);
+  fs::path recovery_filepath = GenerateRecoveryFilePath(root_path, pkg_type);
   if (!AppendString(recovery_filepath.string()))
     return {};
 
@@ -76,7 +76,7 @@ std::string GlobalRecoveryFile::AddPathWithType(
 }
 
 bool GlobalRecoveryFile::AppendPath(
-    const bf::path& additional_path) {
+    const fs::path& additional_path) {
   return AppendString(additional_path.string());
 }
 
@@ -88,7 +88,7 @@ bool GlobalRecoveryFile::AppendString(const std::string& val) {
   if (recovery_filepath_.empty())
     return true;
 
-  if (bf::exists(recovery_filepath_)) {
+  if (fs::exists(recovery_filepath_)) {
     backup_path_ = Backup(recovery_filepath_);
     if (backup_path_.empty()) {
       LOG(ERROR) << "Failed to backup";
@@ -111,20 +111,20 @@ bool GlobalRecoveryFile::AppendString(const std::string& val) {
   return true;
 }
 
-bf::path GlobalRecoveryFile::GenerateRecoveryFilePath(
-    const bf::path& path, const std::string& type) {
-  bf::path pattern = path;
+fs::path GlobalRecoveryFile::GenerateRecoveryFilePath(
+    const fs::path& path, const std::string& type) {
+  fs::path pattern = path;
   pattern += "/";
   pattern += type;
   pattern += "-recovery-%%%%%%";
-  bf::path tmp_path;
+  fs::path tmp_path;
 
   std::vector<std::string>::iterator iter;
   do {
-    tmp_path = boost::filesystem::unique_path(pattern);
+    tmp_path = ci::GenerateUniquePathString(pattern);
     iter = std::find(recovery_list_.begin(), recovery_list_.end(),
         tmp_path.string());
-  } while (boost::filesystem::exists(tmp_path) ||
+  } while (std::filesystem::exists(tmp_path) ||
       iter != recovery_list_.end());
 
   return tmp_path;