Rename backup_paths.h to paths.h
[platform/core/appfw/wgt-backend.git] / src / wgt / step / filesystem / step_wgt_prepare_package_directory.cc
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.
4
5 #include "wgt/step/filesystem/step_wgt_prepare_package_directory.h"
6
7 #include <boost/filesystem/path.hpp>
8 #include <boost/filesystem/operations.hpp>
9 #include <boost/system/system_error.hpp>
10
11 #include <common/paths.h>
12 #include <common/utils/file_util.h>
13
14 namespace bf = boost::filesystem;
15 namespace bs = boost::system;
16 namespace ci = common_installer;
17
18 namespace {
19
20 const char kResWgtDirectory[] = "res/wgt";
21
22 }  // namespace
23
24 namespace wgt {
25 namespace filesystem {
26
27 ci::Step::Status StepWgtPreparePackageDirectory::CreateSymlinkToMountPoint() {
28   bs::error_code error;
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;
35     }
36     bf::remove(res_wgt_link, error);
37     if (error) {
38       LOG(ERROR) << "Failed to remote old symlink to wgt resource directory";
39       return Status::APP_DIR_ERROR;
40     }
41   } else {
42     bf::create_directories(res_wgt_link.parent_path(), error);
43     if (error) {
44       LOG(ERROR) << "Failed to create " << kResWgtDirectory << " directory";
45       return Status::APP_DIR_ERROR;
46     }
47   }
48   bf::create_symlink(mount_point, res_wgt_link, error);
49   if (error) {
50     LOG(ERROR) << "Failed to create symlink to widget image";
51     return Status::APP_DIR_ERROR;
52   }
53   return Status::OK;
54 }
55
56 ci::Step::Status StepWgtPreparePackageDirectory::process() {
57   Status status = CreateSymlinkToMountPoint();
58   if (status != Status::OK)
59     return status;
60   LOG(DEBUG) << "Symlink to mount point created";
61
62   return Status::OK;
63 }
64
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;
69   }
70   return Status::OK;
71 }
72
73 }  // namespace filesystem
74 }  // namespace wgt