1 // Copyright (c) 2016 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_prepare_package_directory.h"
7 #include <boost/filesystem/path.hpp>
8 #include <boost/filesystem/operations.hpp>
9 #include <boost/system/system_error.hpp>
11 #include <common/paths.h>
12 #include <common/utils/file_util.h>
14 namespace bf = boost::filesystem;
15 namespace bs = boost::system;
16 namespace ci = common_installer;
20 const char kResWgtDirectory[] = "res/wgt";
25 namespace filesystem {
27 ci::Step::Status StepWgtPreparePackageDirectory::CreateSymlinkToMountPoint() {
29 bf::path mount_point = ci::GetMountLocation(context_->pkg_path.get());
30 bf::path res_wgt_link = context_->pkg_path.get() / kResWgtDirectory;
31 if (bf::exists(res_wgt_link)) {
32 if (!bf::is_symlink(res_wgt_link)) {
33 LOG(ERROR) << res_wgt_link << " is not symlink. Cannot proceed";
34 return Status::APP_DIR_ERROR;
36 bf::remove(res_wgt_link, error);
38 LOG(ERROR) << "Failed to remote old symlink to wgt resource directory";
39 return Status::APP_DIR_ERROR;
42 bf::create_directories(res_wgt_link.parent_path(), error);
44 LOG(ERROR) << "Failed to create " << kResWgtDirectory << " directory";
45 return Status::APP_DIR_ERROR;
48 bf::create_symlink(mount_point, res_wgt_link, error);
50 LOG(ERROR) << "Failed to create symlink to widget image";
51 return Status::APP_DIR_ERROR;
56 ci::Step::Status StepWgtPreparePackageDirectory::process() {
57 Status status = CreateSymlinkToMountPoint();
58 if (status != Status::OK)
60 LOG(DEBUG) << "Symlink to mount point created";
65 ci::Step::Status StepWgtPreparePackageDirectory::precheck() {
66 if (context_->pkg_path.get().empty()) {
67 LOG(ERROR) << "Package installation path is not set";
68 return Status::INVALID_VALUE;
73 } // namespace filesystem