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/utils/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::CopyAppStorage(
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::CopyDir(src, dst,
37 merge_dirs ? common_installer::FS_MERGE_SKIP |
38 common_installer::FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS
39 : common_installer::FS_NONE, false);
42 common_installer::Step::Status StepCopyStorageDirectories::precheck() {
44 common_installer::GetBackupPathForPackagePath(context_->GetPkgPath());
46 bs::error_code error_code;
47 if (!bf::exists(backup_path_, error_code)) {
48 LOG(DEBUG) << "Cannot restore storage directories from: " << backup_path_;
49 return Status::INVALID_VALUE;
55 common_installer::Step::Status StepCopyStorageDirectories::process() {
56 if (context_->request_mode.get() == RequestMode::GLOBAL)
58 if (!CopyAppStorage(backup_path_,
59 context_->GetPkgPath(),
60 kDataLocation, true)) {
61 LOG(ERROR) << "Failed to restore private directory for widget in update";
62 return Status::APP_DIR_ERROR;
65 if (!CopyAppStorage(backup_path_,
66 context_->GetPkgPath(),
67 kSharedResLocation, true)) {
68 LOG(ERROR) << "Failed to restore shared directory for widget in update";
69 return Status::APP_DIR_ERROR;
73 return Status::APP_DIR_ERROR;
78 bool StepCopyStorageDirectories::CacheDir() {
79 bs::error_code error_code;
80 bf::path cache_path = context_->GetPkgPath() / kCache;
81 bf::create_directory(cache_path, error_code);
83 LOG(ERROR) << "Failed to create cache directory for package";
89 } // namespace filesystem
90 } // namespace common_installer