Implement Cleanup in StepMountRecover 25/286725/2
authorilho kim <ilho159.kim@samsung.com>
Thu, 12 Jan 2023 05:24:27 +0000 (14:24 +0900)
committerilho kim <ilho159.kim@samsung.com>
Fri, 13 Jan 2023 07:30:20 +0000 (07:30 +0000)
Implement Cleanup in StepMountRecover to remove the zip path backed up

Change-Id: Ia9e2d760dfb04598a2780f9410f41ff80c885618
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/common/step/mount/step_mount_recover.cc
src/common/step/mount/step_mount_recover.h

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();
index d74f043..9236b76 100644 (file)
@@ -27,6 +27,7 @@ class StepMountRecover : public MountBase, public recovery::StepRecovery {
   Status RecoveryDelta() override { return Status::OK; }
   Status RecoveryMountNew() override { return Status::OK; }
   Status RecoveryMountUpdate() override;
+  Status Cleanup() override;
 
   Status clean() override;
   Status undo() override;