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 "wgt/step/filesystem/step_wgt_patch_storage_directories.h"
7 #include <boost/filesystem/operations.hpp>
8 #include <boost/filesystem/path.hpp>
9 #include <boost/system/error_code.hpp>
11 #include <common/utils/file_util.h>
13 namespace bf = boost::filesystem;
14 namespace bs = boost::system;
15 namespace ci = common_installer;
19 const char kSharedLocation[] = "shared";
20 const char kSharedResLocation[] = "shared/res";
21 const char kResWgtSubPath[] = "res/wgt";
22 const char kTemporaryData[] = "tmp";
27 namespace filesystem {
29 common_installer::Step::Status StepWgtPatchStorageDirectories::process() {
30 if (!CreatePrivateTmpDir())
31 return Status::APP_DIR_ERROR;
33 int version = std::stoi(context_->manifest_data.get()->api_version);
36 "Moving and linking widget's shared/res directory content in "
37 << context_->pkg_path.get();
39 return Status::APP_DIR_ERROR;
45 bool StepWgtPatchStorageDirectories::ShareDirFor3x() {
46 // check if ${pkg_path}/res/wgt/shared/res exists
47 bf::path wgt_shared_res_dir =
48 context_->pkg_path.get() / kResWgtSubPath / kSharedResLocation;
49 if (!bf::exists(wgt_shared_res_dir))
51 // create ${pkg_path}/shared/res
52 bf::path shared_dir = context_->pkg_path.get() / kSharedLocation;
53 if (!bf::exists(shared_dir)) {
55 bf::create_directory(shared_dir, error);
57 LOG(ERROR) << "Failed to create directory: " << shared_dir;
61 bf::path shared_res_dir = context_->pkg_path.get() / kSharedResLocation;
62 if (!bf::exists(shared_res_dir)) {
64 bf::create_directory(shared_res_dir, error);
66 LOG(ERROR) << "Failed to create directory: " << shared_res_dir;
71 // move and link all contents of ${pkg_path}res/wgt/shared/res
72 // to ${pkg_path}shared/res
73 bf::directory_iterator end_itr;
74 for (bf::directory_iterator itr(wgt_shared_res_dir); itr != end_itr; ++itr) {
75 bf::path current = itr->path();
76 if (bf::is_symlink(current)) {
79 bf::path dest = shared_res_dir / current.filename();
80 if (bf::is_directory(current)) {
81 if (!ci::MoveDir(current, dest, ci::FS_MERGE_OVERWRITE))
84 if (!ci::MoveFile(current, dest, true))
88 bf::create_symlink(dest, current, error);
90 LOG(ERROR) << "linking failed for " << dest
91 << ": " << boost::system::system_error(error).what();
98 bool StepWgtPatchStorageDirectories::CreatePrivateTmpDir() {
99 bf::path tmp_path = context_->pkg_path.get() / kTemporaryData;
100 if (bf::exists(tmp_path) && bf::is_directory(tmp_path)) {
103 bs::error_code error;
104 bf::create_directory(tmp_path, error);
106 LOG(ERROR) << "Failed to create private temporary directory for package";
112 } // namespace filesystem