Implement Cleanup in StepMountRecover
[platform/core/appfw/app-installers.git] / src / common / step / mount / step_mount_recover.cc
index e922b0c..65e1c3b 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <pkgmgrinfo_basic.h>
 
+#include "common/utils/file_util.h"
 #include "common/utils/paths.h"
 #include "common/tzip_interface.h"
 #include "common/zip_interface.h"
@@ -35,6 +36,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;
+
+  bf::path zip_destination_path =
+      GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
+  bf::path backup_zip_location = GetBackupPathForZipFile(zip_destination_path);
+
+  if (bf::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();