From 5735c1a3b8ce997d174ea26a6c048bdc77088ebd Mon Sep 17 00:00:00 2001 From: Wojciech Kosowicz Date: Mon, 3 Aug 2015 11:45:25 +0200 Subject: [PATCH] [Recovery] StepRemoveTemporaryDirectory Step deletes all the directories that starts with 'unpack' within root app directory Change-Id: I22c5b8a3db9fc370876a47a8193a8f5490b48fb9 --- src/common/CMakeLists.txt | 1 + src/common/step/step_remove_temporary_directory.cc | 36 +++++++++++++++++++ src/common/step/step_remove_temporary_directory.h | 40 ++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/common/step/step_remove_temporary_directory.cc create mode 100644 src/common/step/step_remove_temporary_directory.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d3c22d4..e9c876a 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -31,6 +31,7 @@ SET(SRCS step/step_parse.cc step/step_remove_icons.cc step/step_remove_files.cc + step/step_remove_temporary_directory.cc step/step_revoke_security.cc step/step_register_security.cc step/step_unregister_app.cc diff --git a/src/common/step/step_remove_temporary_directory.cc b/src/common/step/step_remove_temporary_directory.cc new file mode 100644 index 0000000..3457a44 --- /dev/null +++ b/src/common/step/step_remove_temporary_directory.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. +#include "common/step/step_remove_temporary_directory.h" + +#include +#include + +#include "common/context_installer.h" + +namespace common_installer { +namespace filesystem { + +namespace bf = boost::filesystem; + +Step::Status StepRemoveTemporaryDirectory::RecoveryUpdate() { + RemoveFiles(); + return Step::Status::OK; +} + +Step::Status StepRemoveTemporaryDirectory::RecoveryNew() { + RemoveFiles(); + return Step::Status::OK; +} + +void StepRemoveTemporaryDirectory::RemoveFiles() { + bf::path unpack_dir_path = context_->unpacked_dir_path.get(); + if (unpack_dir_path.empty()) + return; + boost::system::error_code error_code; + bf::remove_all(unpack_dir_path, error_code); + return; +} +} // namespace filesystem +} // namespace common_installer + diff --git a/src/common/step/step_remove_temporary_directory.h b/src/common/step/step_remove_temporary_directory.h new file mode 100644 index 0000000..af31960 --- /dev/null +++ b/src/common/step/step_remove_temporary_directory.h @@ -0,0 +1,40 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef COMMON_STEP_STEP_REMOVE_TEMPORARY_DIRECTORY_H_ +#define COMMON_STEP_STEP_REMOVE_TEMPORARY_DIRECTORY_H_ + +#include "common/step/step_recovery.h" + +namespace common_installer { +namespace filesystem { + +/** + * @brief removes temp directories if install gets + * interrupted + * + * Part of Recovery Mode. If recovery mode gets called + * path to temporary unpack directory and its content get + * deleted + */ +class StepRemoveTemporaryDirectory : public recovery::StepRecovery { + public: + using StepRecovery::StepRecovery; + + Status RecoveryNew() override; + Status RecoveryUpdate() override; + private: + /** + * @brief RemoveFiles + * Removes all the temporary files + */ + void RemoveFiles(); + + SCOPE_LOG_TAG(RemoveTemporaryDirectory) +}; + +} // namespace filesystem +} // namespace common_installer + +#endif // COMMON_STEP_STEP_REMOVE_TEMPORARY_DIRECTORY_H_ -- 2.7.4