1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/filesystem/step_copy_storage_directories.h"
7 #include <boost/filesystem/path.hpp>
8 #include <boost/system/error_code.hpp>
12 #include "common/paths.h"
13 #include "utils/file_util.h"
15 namespace bf = boost::filesystem;
16 namespace bs = boost::system;
20 const char kCache[] = "cache";
21 const char kDataLocation[] = "data";
22 const char kSharedResLocation[] = "shared";
26 namespace common_installer {
27 namespace filesystem {
29 bool StepCopyStorageDirectories::MoveAppStorage(
30 const bf::path& in_src,
31 const bf::path& in_dst,
34 bf::path src = in_src / key;
35 bf::path dst = in_dst / key;
36 return common_installer::MoveDir(src, dst,
37 merge_dirs ? common_installer::FS_MERGE_SKIP
38 : common_installer::FS_NONE);
41 common_installer::Step::Status StepCopyStorageDirectories::precheck() {
43 common_installer::GetBackupPathForPackagePath(context_->pkg_path.get());
45 bs::error_code error_code;
46 if (!bf::exists(backup_path_, error_code)) {
47 LOG(DEBUG) << "Cannot restore storage directories from: " << backup_path_;
48 return Status::INVALID_VALUE;
54 common_installer::Step::Status StepCopyStorageDirectories::process() {
55 if (context_->request_mode.get() == RequestMode::GLOBAL)
57 if (!MoveAppStorage(backup_path_,
58 context_->pkg_path.get(),
59 kDataLocation, true)) {
60 LOG(ERROR) << "Failed to restore private directory for widget in update";
61 return Status::APP_DIR_ERROR;
64 if (!MoveAppStorage(backup_path_,
65 context_->pkg_path.get(),
66 kSharedResLocation, true)) {
67 LOG(ERROR) << "Failed to restore shared directory for widget in update";
68 return Status::APP_DIR_ERROR;
72 return Status::APP_DIR_ERROR;
77 common_installer::Step::Status StepCopyStorageDirectories::undo() {
78 if (context_->request_mode.get() == RequestMode::GLOBAL)
80 common_installer::Step::Status ret = Status::OK;
81 if (!MoveAppStorage(context_->pkg_path.get(),
84 LOG(ERROR) << "Failed to restore private directory for package in update";
85 ret = Status::APP_DIR_ERROR;
88 if (!MoveAppStorage(context_->pkg_path.get(),
90 kSharedResLocation)) {
91 LOG(ERROR) << "Failed to restore shared directory for package in update";
92 ret = Status::APP_DIR_ERROR;
98 bool StepCopyStorageDirectories::CacheDir() {
99 bs::error_code error_code;
100 bf::path cache_path = context_->pkg_path.get() / kCache;
101 bf::create_directory(cache_path, error_code);
103 LOG(ERROR) << "Failed to create cache directory for package";
109 } // namespace filesystem
110 } // namespace common_installer