Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / rds / step_rds_modify.cc
index de6736f..018595d 100644 (file)
@@ -4,18 +4,18 @@
 
 #include "common/step/rds/step_rds_modify.h"
 
-#include <boost/system/error_code.hpp>
-
 #include <manifest_parser/utils/logging.h>
 
-#include <common/utils/file_util.h>
+#include <filesystem>
+
+#include "common/utils/file_util.h"
+
+namespace ci = common_installer;
+namespace fs = std::filesystem;
 
 namespace common_installer {
 namespace rds {
 
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
-namespace ci = common_installer;
 
 StepRDSModify::StepRDSModify(InstallerContext* context)
     : Step(context) {}
@@ -25,7 +25,7 @@ Step::Status StepRDSModify::precheck() {
     LOG(ERROR) << "unpacked dir path is not set";
     return common_installer::Step::Status::INVALID_VALUE;
   }
-  if (!bf::exists(context_->unpacked_dir_path.get())) {
+  if (!fs::exists(context_->unpacked_dir_path.get())) {
     LOG(ERROR) << "unpacked_dir_path ("
                << context_->unpacked_dir_path.get()
                << ") path does not exist";
@@ -52,8 +52,8 @@ Step::Status StepRDSModify::process() {
     LOG(ERROR) << "unable to setup temp directory";
     return Step::Status::ERROR;
   }
-  bf::path install_path = context_->GetPkgPath();
-  bf::path unzip_path = context_->unpacked_dir_path.get();
+  fs::path install_path = context_->GetPkgPath();
+  fs::path unzip_path = context_->unpacked_dir_path.get();
   if (!AddFiles(unzip_path, install_path) ||
      !ModifyFiles(unzip_path, install_path) ||
      !DeleteFiles(install_path)) {
@@ -73,29 +73,29 @@ Step::Status StepRDSModify::clean() {
   return Step::Status::OK;
 }
 
-bool StepRDSModify::AddFiles(bf::path unzip_path, bf::path install_path) {
+bool StepRDSModify::AddFiles(fs::path unzip_path, fs::path install_path) {
   LOG(INFO) << "about to add files";
-  bs::error_code error;
+  std::error_code error;
   for (const auto& file : context_->files_to_add.get()) {
     if (!PerformBackup(file, Operation::ADD)) {
       LOG(ERROR) << "unable to perform backup of added file";
       return false;
     }
-    bf::path temp_install_path(install_path / file);
-    if (bf::is_directory(temp_install_path)) {
-      if (!bf::exists(temp_install_path) &&
+    fs::path temp_install_path(install_path / file);
+    if (fs::is_directory(temp_install_path)) {
+      if (!fs::exists(temp_install_path) &&
          (!CreateDir(temp_install_path))) {
         LOG(ERROR) << "unable to create dir for temp backup data";
         return false;
       }
     } else {
-      if (!bf::exists(temp_install_path.parent_path()) &&
+      if (!fs::exists(temp_install_path.parent_path()) &&
           !CreateDir(temp_install_path.parent_path())) {
         LOG(ERROR) << "unable to create dir for temp backup data";
         return false;
       }
-      bf::path temp_unzip_path(unzip_path / file);
-      bf::copy_file(temp_unzip_path, temp_install_path, error);
+      fs::path temp_unzip_path(unzip_path / file);
+      fs::copy_file(temp_unzip_path, temp_install_path, error);
       if (error) {
         LOG(ERROR) << "unable to add file " << error.message();
         return false;
@@ -105,18 +105,18 @@ bool StepRDSModify::AddFiles(bf::path unzip_path, bf::path install_path) {
   return true;
 }
 
-bool StepRDSModify::ModifyFiles(bf::path unzip_path, bf::path install_path) {
+bool StepRDSModify::ModifyFiles(fs::path unzip_path, fs::path install_path) {
   LOG(INFO) << "about to modify files";
-  bs::error_code error;
+  std::error_code error;
   for (const auto& file : context_->files_to_modify.get()) {
-    bf::path temp_install_path(install_path / file);
-    bf::path temp_unzip_path(unzip_path / file);
+    fs::path temp_install_path(install_path / file);
+    fs::path temp_unzip_path(unzip_path / file);
     if (!PerformBackup(file, Operation::MODIFY)) {
       LOG(ERROR) << "unable to perform backup of to be modified file";
       return false;
     }
-    bf::copy_file(temp_unzip_path, temp_install_path,
-                  bf::copy_option::overwrite_if_exists, error);
+    fs::copy_file(temp_unzip_path, temp_install_path,
+                  fs::copy_options::overwrite_existing, error);
     if (error) {
       LOG(ERROR) << "unable to modify file " << error.message();
       return false;
@@ -125,7 +125,7 @@ bool StepRDSModify::ModifyFiles(bf::path unzip_path, bf::path install_path) {
   return true;
 }
 
-bool StepRDSModify::DeleteFiles(bf::path install_path) {
+bool StepRDSModify::DeleteFiles(fs::path install_path) {
   LOG(INFO) << "about to delete files";
   for (const auto& file : context_->files_to_delete.get()) {
     if (!PerformBackup(file, Operation::DELETE)) {
@@ -140,10 +140,9 @@ bool StepRDSModify::DeleteFiles(bf::path install_path) {
 
 bool StepRDSModify::SetUpTempBackupDir() {
   LOG(INFO) << "about to setup tmp backup dir";
-  bs::error_code error;
   backup_temp_dir_ = "/tmp/" /
-      bf::unique_path("%%%%-%%%%-%%%%-%%%%", error);
-  if (error || !CreateDir(backup_temp_dir_)) {
+      ci::GenerateUniquePathString("%%%%-%%%%-%%%%-%%%%");
+  if (!CreateDir(backup_temp_dir_)) {
     LOG(ERROR) << "unable to create backup data temp dir";
     return false;
   }
@@ -156,22 +155,22 @@ bool StepRDSModify::PerformBackup(std::string relative_path,
   if (backup_temp_dir_.empty())
     return false;
   if (operation == Operation::DELETE || operation == Operation::MODIFY) {
-    bf::path app_path = context_->GetPkgPath();
-    bf::path source_path = app_path  / relative_path;
-    if (bf::is_directory(source_path)) {
+    fs::path app_path = context_->GetPkgPath();
+    fs::path source_path = app_path  / relative_path;
+    if (fs::is_directory(source_path)) {
       if (!CreateDir(backup_temp_dir_ / relative_path)) {
         LOG(ERROR) << "unable to create dir for temp backup data";
         return false;
       }
     } else {
-      bs::error_code error;
-      bf::path tmp_dest_path = backup_temp_dir_ / relative_path;
-      if (!bf::exists((tmp_dest_path).parent_path()) &&
+      std::error_code error;
+      fs::path tmp_dest_path = backup_temp_dir_ / relative_path;
+      if (!fs::exists((tmp_dest_path).parent_path()) &&
         (!CreateDir((tmp_dest_path).parent_path()))) {
         LOG(ERROR) << "unable to create dir for temp backup data";
         return false;
       }
-      bf::copy_file(source_path, tmp_dest_path, error);
+      fs::copy_file(source_path, tmp_dest_path, error);
       if (error) {
         LOG(ERROR) << "unable to backup file: "
                    << source_path << " : " << error.message();
@@ -185,32 +184,32 @@ bool StepRDSModify::PerformBackup(std::string relative_path,
 
 void StepRDSModify::RestoreFiles() {
   LOG(ERROR) << "error occured about to restore files";
-  bf::path app_path(context_->GetPkgPath());
+  fs::path app_path(context_->GetPkgPath());
   for (std::pair<std::string, Operation>& modification :
        success_modifications_) {
-    bf::path source_path(backup_temp_dir_ / modification.first);
-    bf::path destination_path(app_path / modification.first);
+    fs::path source_path(backup_temp_dir_ / modification.first);
+    fs::path destination_path(app_path / modification.first);
     if (modification.second == Operation::ADD) {
-      if (bf::is_directory(source_path)) {
-        bf::remove_all(destination_path);
+      if (fs::is_directory(source_path)) {
+        fs::remove_all(destination_path);
       } else {
-        bf::remove(destination_path);
+        fs::remove(destination_path);
       }
     } else if (modification.second == Operation::MODIFY) {
-      bf::copy_file(source_path, destination_path,
-                    bf::copy_option::overwrite_if_exists);
+      fs::copy_file(source_path, destination_path,
+                    fs::copy_options::overwrite_existing);
     } else {
-      if (bf::is_directory(source_path)) {
+      if (fs::is_directory(source_path)) {
         if (!CreateDir(destination_path))
           LOG(ERROR) << "Failed to create dir: " << destination_path;
       } else {
-        bf::copy_file(source_path, destination_path,
-                      bf::copy_option::overwrite_if_exists);
+        fs::copy_file(source_path, destination_path,
+                      fs::copy_options::overwrite_existing);
       }
     }
   }
   // after files are restore delete temporary location
-  bf::remove_all(backup_temp_dir_);
+  fs::remove_all(backup_temp_dir_);
 }
 
 }  // namespace rds