Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / backup / step_backup_manifest.cc
index bc1fa54..fdaad81 100644 (file)
@@ -4,46 +4,43 @@
 
 #include "common/step/backup/step_backup_manifest.h"
 
-#include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/system/error_code.hpp>
-
 #include <pkgmgr-info.h>
 #include <pkgmgr_installer.h>
 
 #include <algorithm>
+#include <filesystem>
 #include <string>
+#include <system_error>
 
 #include "common/utils/paths.h"
 #include "common/utils/file_util.h"
 
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
 namespace ci = common_installer;
+namespace fs = std::filesystem;
 
 namespace common_installer {
 namespace backup {
 
 Step::Status StepBackupManifest::precheck() {
-  if (!bf::exists(context_->xml_path.get())) {
+  if (!fs::exists(context_->xml_path.get())) {
     LOG(ERROR) << "Xml manifest file does not exist";
     return Status::MANIFEST_NOT_FOUND;
   }
+
   return Status::OK;
 }
 
 Step::Status StepBackupManifest::process() {
   // set backup file path
-  bf::path backup_xml_path =
+  fs::path backup_xml_path =
       GetBackupPathForManifestFile(context_->xml_path.get());
   context_->backup_xml_path.set(backup_xml_path);
-  bs::error_code error;
-  bf::copy_file(context_->xml_path.get(), context_->backup_xml_path.get(),
-                bf::copy_option::overwrite_if_exists, error);
-  if (error) {
+  if (!MoveFile(context_->xml_path.get(), backup_xml_path, true) ||
+      !CopyFile(backup_xml_path, context_->xml_path.get())) {
     LOG(ERROR) << "Failed to make a copy of xml manifest file";
     return Status::MANIFEST_ERROR;
   }
+
   LOG(DEBUG) << "Manifest backup created";
   return Status::OK;
 }
@@ -51,24 +48,27 @@ Step::Status StepBackupManifest::process() {
 Step::Status StepBackupManifest::clean() {
   LOG(DEBUG) << "Remove manifest backup";
   ci::Remove(context_->backup_xml_path.get());
+
   return Status::OK;
 }
 
 Step::Status StepBackupManifest::undo() {
-  if (bf::exists(context_->backup_xml_path.get())) {
-    bs::error_code error;
-    bf::remove(context_->xml_path.get(), error);
-    if (error) {
-      LOG(ERROR) << "Failed to remove newly generated xml file in revert";
-      return Status::MANIFEST_ERROR;
-    }
-    if (!MoveFile(context_->backup_xml_path.get(),
-        context_->xml_path.get())) {
-      LOG(ERROR) << "Failed to revert a content of xml manifest file";
-      return Status::MANIFEST_ERROR;
-    }
-    LOG(DEBUG) << "Manifest reverted from backup";
+  if (!fs::exists(context_->backup_xml_path.get()))
+    return Status::OK;
+
+  std::error_code error;
+  fs::remove(context_->xml_path.get(), error);
+  if (error) {
+    LOG(ERROR) << "Failed to remove newly generated xml file in revert";
+    return Status::MANIFEST_ERROR;
   }
+  if (!MoveFile(context_->backup_xml_path.get(),
+      context_->xml_path.get())) {
+    LOG(ERROR) << "Failed to revert a content of xml manifest file";
+    return Status::MANIFEST_ERROR;
+  }
+  LOG(DEBUG) << "Manifest reverted from backup";
+
   return Status::OK;
 }