1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a apache 2.0 license that can be
4 // found in the LICENSE file.
6 #include "common/step/filesystem/step_copy_tep.h"
12 #include "common/utils/paths.h"
13 #include "common/utils/file_util.h"
15 namespace common_installer {
16 namespace filesystem {
18 namespace bf = boost::filesystem;
19 namespace bs = boost::system;
21 Step::Status StepCopyTep::precheck() {
22 if (context_->root_application_path.get().empty()) {
23 LOG(ERROR) << "root_application_path attribute is empty";
24 return Step::Status::INVALID_VALUE;
27 if (!boost::filesystem::exists(context_->root_application_path.get())) {
28 LOG(ERROR) << "root_application_path ("
29 << context_->root_application_path.get()
30 << ") path does not exist";
31 return Step::Status::INVALID_VALUE;
34 if (context_->pkgid.get().empty()) {
35 LOG(ERROR) << "pkgid attribute is empty";
36 return Step::Status::INVALID_VALUE;
39 return Step::Status::OK;
42 Step::Status StepCopyTep::process() {
43 if (context_->tep_path.get().empty())
44 return Step::Status::OK;
46 if (context_->external_storage) {
47 tep_path = GetExternalTepPath(context_->request_mode.get(),
50 tep_path = GetInternalTepPath(context_->GetPkgPath());
53 // Keep filename of app store supplied file. Filename contains hash that
54 // appstore uses to identify version of tep on device.
55 tep_path /= context_->tep_path.get().filename();
57 if (!bf::exists(tep_path.parent_path())) {
59 bf::create_directories(tep_path.parent_path(), error);
61 LOG(ERROR) << "Cannot create tep parent directory";
62 return Status::APP_DIR_ERROR;
66 if (context_->is_tep_move.get()) {
67 if (!MoveFile(context_->tep_path.get(), tep_path)) {
68 LOG(ERROR) << "Cannnot move TEP file into install path";
69 return Step::Status::APP_DIR_ERROR;
72 if (!CopyFile(context_->tep_path.get(), tep_path)) {
73 LOG(ERROR) << "Cannot copy TEP file [" << context_->tep_path.get() <<
74 "] into install path [" << tep_path << "]";
75 return Step::Status::APP_DIR_ERROR;
78 context_->tep_path.set(tep_path);
79 context_->manifest_data.get()->tep_name =
80 strdup(context_->tep_path.get().c_str());
82 return Step::Status::OK;
85 Step::Status StepCopyTep::undo() {
86 RemoveAll(context_->tep_path.get());
87 // remove tep file is installed outside package path
88 if (context_->external_storage) {
89 bf::path tep_path = GetExternalTepPath(context_->request_mode.get(),
91 tep_path /= context_->tep_path.get().filename();
97 } // namespace filesystem
98 } // namespace common_installer