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 <system_error>
14 #include "common/utils/paths.h"
15 #include "common/utils/file_util.h"
17 namespace common_installer {
18 namespace filesystem {
20 namespace fs = std::filesystem;
22 Step::Status StepCopyTep::precheck() {
23 if (context_->root_application_path.get().empty()) {
24 LOG(ERROR) << "root_application_path attribute is empty";
25 return Step::Status::INVALID_VALUE;
28 if (!std::filesystem::exists(context_->root_application_path.get())) {
29 LOG(ERROR) << "root_application_path ("
30 << context_->root_application_path.get()
31 << ") path does not exist";
32 return Step::Status::INVALID_VALUE;
35 if (context_->pkgid.get().empty()) {
36 LOG(ERROR) << "pkgid attribute is empty";
37 return Step::Status::INVALID_VALUE;
40 return Step::Status::OK;
43 Step::Status StepCopyTep::process() {
44 if (context_->tep_path.get().empty())
45 return Step::Status::OK;
47 if (context_->external_storage) {
48 tep_path = GetExternalTepPath(context_->request_mode.get(),
51 tep_path = GetInternalTepPath(context_->GetPkgPath());
54 // Keep filename of app store supplied file. Filename contains hash that
55 // appstore uses to identify version of tep on device.
56 tep_path /= context_->tep_path.get().filename();
58 if (!fs::exists(tep_path.parent_path())) {
59 std::error_code error;
60 fs::create_directories(tep_path.parent_path(), error);
62 LOG(ERROR) << "Cannot create tep parent directory";
63 return Status::APP_DIR_ERROR;
67 if (context_->is_tep_move.get()) {
68 if (!MoveFile(context_->tep_path.get(), tep_path)) {
69 LOG(ERROR) << "Cannnot move TEP file into install path";
70 return Step::Status::APP_DIR_ERROR;
73 if (!CopyFile(context_->tep_path.get(), tep_path)) {
74 LOG(ERROR) << "Cannot copy TEP file [" << context_->tep_path.get() <<
75 "] into install path [" << tep_path << "]";
76 return Step::Status::APP_DIR_ERROR;
79 context_->tep_path.set(tep_path);
80 context_->manifest_data.get()->tep_name =
81 strdup(context_->tep_path.get().c_str());
83 return Step::Status::OK;
86 Step::Status StepCopyTep::undo() {
87 RemoveAll(context_->tep_path.get());
88 // remove tep file is installed outside package path
89 if (context_->external_storage) {
90 fs::path tep_path = GetExternalTepPath(context_->request_mode.get(),
92 tep_path /= context_->tep_path.get().filename();
98 } // namespace filesystem
99 } // namespace common_installer