Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / mount / step_mount_recover.cc
index e922b0c..be839f6 100644 (file)
@@ -4,28 +4,28 @@
 
 #include "step/mount/step_mount_recover.h"
 
-#include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>
-
 #include <pkgmgrinfo_basic.h>
 
+#include <filesystem>
+
+#include "common/utils/file_util.h"
 #include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
 
-namespace bf = boost::filesystem;
+namespace fs = std::filesystem;
 
 namespace common_installer {
 namespace mount {
 
 Step::Status StepMountRecover::RecoveryMountUpdate() {
-  bf::path zip_destination_path =
+  fs::path zip_destination_path =
       GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
   manifest_x* manifest = context_->manifest_data.get();
   if (manifest)
     manifest->zip_mount_file = strdup(zip_destination_path.c_str());
 
-  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
+  fs::path mount_point = GetMountLocation(context_->GetPkgPath());
   auto zip_final = CreateZipInterface(mount_point);
   if (!zip_final->MountZip(zip_destination_path)) {
     LOG(ERROR) << "Failed to mount zip package in installation path";
@@ -35,6 +35,32 @@ Step::Status StepMountRecover::RecoveryMountUpdate() {
   return Status::OK;
 }
 
+Step::Status StepMountRecover::Cleanup() {
+  recovery::RecoveryFile* recovery_file =
+      context_->recovery_info.get().recovery_file.get();
+  if (!recovery_file) {
+    LOG(ERROR) << "Failed to get recovery info";
+    return Status::RECOVERY_ERROR;
+  }
+
+  if (recovery_file->type() != RequestType::MountUpdate)
+    return Status::OK;
+
+  fs::path zip_destination_path =
+      GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
+  fs::path backup_zip_location = GetBackupPathForZipFile(zip_destination_path);
+
+  if (fs::exists(backup_zip_location)) {
+    if (!Remove(backup_zip_location)) {
+      LOG(ERROR) << "Fail to remove backup zip location : "
+          << backup_zip_location;
+      return Status::RECOVERY_ERROR;
+    }
+  }
+
+  return Status::OK;
+}
+
 Step::Status StepMountRecover::clean() {
   recovery::RecoveryFile* recovery_file =
       context_->recovery_info.get().recovery_file.get();
@@ -66,7 +92,7 @@ Step::Status StepMountRecover::undo() {
 }
 
 Step::Status StepMountRecover::UmountPackagePath() {
-  bf::path mount_point = GetMountLocation(context_->GetPkgPath());
+  fs::path mount_point = GetMountLocation(context_->GetPkgPath());
   auto zip_final = CreateZipInterface(mount_point);
   if (!zip_final->UnmountZip()) {
     LOG(ERROR) << "Failed to unmount zip package after installation";
@@ -77,7 +103,7 @@ Step::Status StepMountRecover::UmountPackagePath() {
 }
 
 std::unique_ptr<IZipInterface> StepMountRecover::CreateZipInterface(
-    const boost::filesystem::path& mount_path) {
+    const std::filesystem::path& mount_path) {
   std::unique_ptr<IZipInterface> zip_interface(
       new TzipInterface(mount_path));
   return zip_interface;