From 3343bb382d7bae849c89a6c26f2fa12f83366e21 Mon Sep 17 00:00:00 2001 From: Ilho Kim Date: Thu, 22 Dec 2022 15:00:01 +0900 Subject: [PATCH] Change the file remove to a virtual function in recovery Change-Id: I33cf3ba4141c5599dfe44c73a4c13847e16f49e0 Signed-off-by: Ilho Kim --- src/common/step/filesystem/step_recover_files.cc | 16 ++++++++++------ src/common/step/filesystem/step_recover_files.h | 5 +++++ .../step/filesystem/step_remove_temporary_directory.cc | 12 ++++++++---- .../step/filesystem/step_remove_temporary_directory.h | 6 ++++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/common/step/filesystem/step_recover_files.cc b/src/common/step/filesystem/step_recover_files.cc index 5bd1ff8..8c22cba 100644 --- a/src/common/step/filesystem/step_recover_files.cc +++ b/src/common/step/filesystem/step_recover_files.cc @@ -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 diff --git a/src/common/step/filesystem/step_recover_files.h b/src/common/step/filesystem/step_recover_files.h index c844ff3..0b1dcd3 100644 --- a/src/common/step/filesystem/step_recover_files.h +++ b/src/common/step/filesystem/step_recover_files.h @@ -5,6 +5,8 @@ #ifndef COMMON_STEP_FILESYSTEM_STEP_RECOVER_FILES_H_ #define COMMON_STEP_FILESYSTEM_STEP_RECOVER_FILES_H_ +#include + #include #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) }; diff --git a/src/common/step/filesystem/step_remove_temporary_directory.cc b/src/common/step/filesystem/step_remove_temporary_directory.cc index 98b52b6..626b887 100644 --- a/src/common/step/filesystem/step_remove_temporary_directory.cc +++ b/src/common/step/filesystem/step_remove_temporary_directory.cc @@ -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 diff --git a/src/common/step/filesystem/step_remove_temporary_directory.h b/src/common/step/filesystem/step_remove_temporary_directory.h index fd5ae94..75fca26 100644 --- a/src/common/step/filesystem/step_remove_temporary_directory.h +++ b/src/common/step/filesystem/step_remove_temporary_directory.h @@ -5,6 +5,8 @@ #ifndef COMMON_STEP_FILESYSTEM_STEP_REMOVE_TEMPORARY_DIRECTORY_H_ #define COMMON_STEP_FILESYSTEM_STEP_REMOVE_TEMPORARY_DIRECTORY_H_ +#include + #include #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 -- 2.7.4