Change the file remove to a virtual function in recovery 86/285886/1
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 22 Dec 2022 06:00:01 +0000 (15:00 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 22 Dec 2022 06:00:01 +0000 (15:00 +0900)
Change-Id: I33cf3ba4141c5599dfe44c73a4c13847e16f49e0
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/step/filesystem/step_recover_files.cc
src/common/step/filesystem/step_recover_files.h
src/common/step/filesystem/step_remove_temporary_directory.cc
src/common/step/filesystem/step_remove_temporary_directory.h

index 5bd1ff8..8c22cba 100644 (file)
@@ -44,7 +44,7 @@ namespace common_installer {
 namespace filesystem {
 
 Step::Status StepRecoverFiles::RecoveryNew() {
-  if (!RemoveAll(context_->GetPkgPath()))
+  if (!ClearPath(context_->GetPkgPath()))
     return Status::RECOVERY_ERROR;
 
   LOG(INFO) << "Package files recovery done";
@@ -64,7 +64,7 @@ Step::Status StepRecoverFiles::RecoveryUpdate() {
         if (iter->path().filename() == kExternalMemoryMountPoint)
           continue;
 
-        if (!RemoveAll(iter->path())) {
+        if (!ClearPath(iter->path())) {
           LOG(ERROR) << "Cannot restore widget files to its correct location";
           return Status::RECOVERY_ERROR;
         }
@@ -81,7 +81,7 @@ Step::Status StepRecoverFiles::RecoveryUpdate() {
         return Status::RECOVERY_ERROR;
     }
 
-    RemoveAll(backup_path);
+    ClearPath(backup_path);
   }
   LOG(INFO) << "Package files recovery done";
   return Status::OK;
@@ -91,7 +91,7 @@ Step::Status StepRecoverFiles::RecoveryMountNew() {
   bf::path zip_location = GetZipPackageLocation(
         context_->GetPkgPath(), context_->pkgid.get());
   Remove(zip_location);
-  RemoveAll(context_->GetPkgPath());
+  ClearPath(context_->GetPkgPath());
   LOG(INFO) << "Package files recovery done";
   return Status::OK;
 }
@@ -129,7 +129,7 @@ Step::Status StepRecoverFiles::RecoveryReadonlyUpdateInstall() {
   bf::path pkg_path =
       bf::path(GetRootAppPath(false, context_->uid.get())) /
       context_->pkgid.get();
-  if (!RemoveAll(pkg_path))
+  if (!ClearPath(pkg_path))
     return Status::RECOVERY_ERROR;
 
   LOG(INFO) << "Package files recovery done";
@@ -146,7 +146,7 @@ Step::Status StepRecoverFiles::Cleanup() {
   if (!bf::exists(backup_path))
     return Status::OK;
 
-  if (!RemoveAll(backup_path)) {
+  if (!ClearPath(backup_path)) {
     LOG(ERROR) << "Failed to remove backup path";
     return Status::RECOVERY_ERROR;
   }
@@ -154,6 +154,10 @@ Step::Status StepRecoverFiles::Cleanup() {
   return Status::OK;
 }
 
+bool StepRecoverFiles::ClearPath(const bf::path& path) {
+  return RemoveAll(path);
+}
+
 }  // namespace filesystem
 }  // namespace common_installer
 
index c844ff3..0b1dcd3 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef COMMON_STEP_FILESYSTEM_STEP_RECOVER_FILES_H_
 #define COMMON_STEP_FILESYSTEM_STEP_RECOVER_FILES_H_
 
+#include <boost/filesystem/path.hpp>
+
 #include <manifest_parser/utils/logging.h>
 
 #include "common/installer_context.h"
@@ -32,6 +34,9 @@ class StepRecoverFiles : public recovery::StepRecovery {
   Status RecoveryReadonlyUpdateInstall() override;
   Status Cleanup() override;
 
+ protected:
+  virtual bool ClearPath(const boost::filesystem::path& path);
+
   STEP_NAME(RecoverFiles)
 };
 
index 98b52b6..626b887 100644 (file)
@@ -36,14 +36,18 @@ Step::Status StepRemoveTemporaryDirectory::RemoveFiles() {
   shared_res_backup_dir_path += ".SharedRes";
   if (unpack_dir_path.empty())
     return Step::Status::OK;
-  if (!RemoveAll(unpack_dir_path) ||
-      !RemoveAll(patch_dir_path) ||
-      !RemoveAll(mount_dir_path) ||
-      !RemoveAll(shared_res_backup_dir_path))
+  if (!ClearPath(unpack_dir_path) ||
+      !ClearPath(patch_dir_path) ||
+      !ClearPath(mount_dir_path) ||
+      !ClearPath(shared_res_backup_dir_path))
     return Step::Status::RECOVERY_ERROR;
   return Step::Status::OK;
 }
 
+bool StepRemoveTemporaryDirectory::ClearPath(const bf::path& path) {
+  return RemoveAll(path);
+}
+
 }  // namespace filesystem
 }  // namespace common_installer
 
index fd5ae94..75fca26 100644 (file)
@@ -5,6 +5,8 @@
 #ifndef COMMON_STEP_FILESYSTEM_STEP_REMOVE_TEMPORARY_DIRECTORY_H_
 #define COMMON_STEP_FILESYSTEM_STEP_REMOVE_TEMPORARY_DIRECTORY_H_
 
+#include <boost/filesystem/path.hpp>
+
 #include <manifest_parser/utils/logging.h>
 
 #include "common/step/recovery/step_recovery.h"
@@ -27,6 +29,10 @@ class StepRemoveTemporaryDirectory : public recovery::StepRecovery {
   Status RecoveryNew() override;
   Status RecoveryUpdate() override;
   Status Cleanup() override;
+
+ protected:
+  virtual bool ClearPath(const boost::filesystem::path& path);
+
  private:
   /**
    * @brief RemoveFiles