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"
9 #include <system_error>
11 #include "common/utils/paths.h"
12 #include "utils/file_util.h"
14 namespace fs = std::filesystem;
18 const char kCache[] = "cache";
19 const char kDataLocation[] = "data";
20 const char kSharedResLocation[] = "shared";
24 namespace common_installer {
25 namespace filesystem {
27 bool StepCopyStorageDirectories::CopyAppStorage(
28 const fs::path& in_src,
29 const fs::path& in_dst,
32 fs::path src = in_src / key;
33 fs::path dst = in_dst / key;
34 return common_installer::CopyDir(src, dst,
35 merge_dirs ? common_installer::FS_MERGE_SKIP |
36 common_installer::FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS
37 : common_installer::FS_NONE, false);
40 common_installer::Step::Status StepCopyStorageDirectories::precheck() {
42 common_installer::GetBackupPathForPackagePath(context_->GetPkgPath());
44 std::error_code error_code;
45 if (!fs::exists(backup_path_, error_code)) {
46 LOG(DEBUG) << "Cannot restore storage directories from: " << backup_path_;
47 return Status::INVALID_VALUE;
53 common_installer::Step::Status StepCopyStorageDirectories::process() {
54 if (context_->request_mode.get() == RequestMode::GLOBAL)
56 if (!CopyAppStorage(backup_path_,
57 context_->GetPkgPath(),
58 kDataLocation, true)) {
59 LOG(ERROR) << "Failed to restore private directory for widget in update";
60 return Status::APP_DIR_ERROR;
63 if (!CopyAppStorage(backup_path_,
64 context_->GetPkgPath(),
65 kSharedResLocation, true)) {
66 LOG(ERROR) << "Failed to restore shared directory for widget in update";
67 return Status::APP_DIR_ERROR;
71 return Status::APP_DIR_ERROR;
76 bool StepCopyStorageDirectories::CacheDir() {
77 std::error_code error_code;
78 fs::path cache_path = context_->GetPkgPath() / kCache;
79 fs::create_directory(cache_path, error_code);
81 LOG(ERROR) << "Failed to create cache directory for package";
87 } // namespace filesystem
88 } // namespace common_installer