From: Wojciech Kosowicz Date: Tue, 4 Aug 2015 08:46:26 +0000 (+0200) Subject: [Recovery] StepRecoverStorageDirectories X-Git-Tag: accepted/tizen/mobile/20150814.112914~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc375c319d41c09db4ffff749785936657fcb92f;p=platform%2Fcore%2Fappfw%2Fapp-installers.git [Recovery] StepRecoverStorageDirectories Change-Id: I7a9c24ca27646d9e285da00bde06b7465b2e9e1c --- diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index fef07eb..338d845 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -22,6 +22,7 @@ SET(SRCS step/step_recover_files.cc step/step_recover_icons.cc step/step_recover_manifest.cc + step/step_recover_storage_directories.cc step/step_recovery.cc step/step_register_app.cc step/step_old_manifest.cc diff --git a/src/common/step/step_recover_storage_directories.cc b/src/common/step/step_recover_storage_directories.cc new file mode 100644 index 0000000..4b74539 --- /dev/null +++ b/src/common/step/step_recover_storage_directories.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache-2.0 license that can be +// found in the LICENSE file. + +#include "common/step/step_recover_storage_directories.h" + +#include +#include + +#include "common/utils/file_util.h" + +namespace { +const char kDataLocation[] = "data"; +const char kSharedLocation[] = "shared"; +} // namespace + +namespace bf = boost::filesystem; + +namespace common_installer { +namespace filesystem { + +bool StepRecoverStorageDirectories::MoveAppStorage( + const bf::path& in_src, + const bf::path& in_dst, + const char *key) { + bf::path src = in_src / key; + bf::path dst = in_dst / key; + return common_installer::MoveDir(src, dst); +} + +Step::Status StepRecoverStorageDirectories::RecoveryUpdate() { + if (!context_->pkg_path.get().empty()) { + bf::path backup_path = common_installer::GetBackupPathForPackagePath( + context_->pkg_path.get()); + if (!backup_path.empty()) { + MoveAppStorage(context_->pkg_path.get(), backup_path, kDataLocation); + MoveAppStorage(context_->pkg_path.get(), backup_path, kSharedLocation); + } + } + return Status::OK; +} +} // namespace filesystem +} // namespace common_installer + diff --git a/src/common/step/step_recover_storage_directories.h b/src/common/step/step_recover_storage_directories.h new file mode 100644 index 0000000..7b3da48 --- /dev/null +++ b/src/common/step/step_recover_storage_directories.h @@ -0,0 +1,45 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by an apache-2.0 license that can be +// found in the LICENSE file. + +#ifndef COMMON_STEP_STEP_RECOVER_STORAGE_DIRECTORIES_H_ +#define COMMON_STEP_STEP_RECOVER_STORAGE_DIRECTORIES_H_ + +#include "common/context_installer.h" +#include "common/step/step_recovery.h" +#include "common/utils/logging.h" + +namespace common_installer { +namespace filesystem { + +/** + * @brief recovers data and shared directories of application + * + * Part of Recovery Mode. Is responsible for restoring data and shared + * directories in case partial update occurs. + */ +class StepRecoverStorageDirectories : public recovery::StepRecovery { + public: + using StepRecovery::StepRecovery; + + Status RecoveryNew() override { return Status::OK; } + Status RecoveryUpdate() override; + private: + /** + * @brief moves directories + * @param in_src path of the source location + * @param in_dst path of the destination location + * @param key directory name + * @return true if operation successful + */ + bool MoveAppStorage(const boost::filesystem::path& in_src, + const boost::filesystem::path& in_dst, + const char *key); + + SCOPE_LOG_TAG(RecoverStorageDirectories) +}; + +} // namespace filesystem +} // namespace common_installer + +#endif // COMMON_STEP_STEP_RECOVER_STORAGE_DIRECTORIES_H_