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.h"
12 #include "common/shared_dirs.h"
13 #include "common/utils/file_util.h"
15 namespace bf = boost::filesystem;
16 namespace bs = boost::system;
17 namespace ci = common_installer;
19 namespace common_installer {
20 namespace filesystem {
22 Step::Status StepCopy::precheck() {
23 if (context_->root_application_path.get().empty()) {
24 LOG(ERROR) << "root_application_path attribute is empty";
25 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_->unpacked_dir_path.get().empty()) {
35 LOG(ERROR) << "unpacked_dir_path attribute is empty";
36 return Step::Status::INVALID_VALUE;
38 if (!boost::filesystem::exists(context_->unpacked_dir_path.get())) {
39 LOG(ERROR) << "unpacked_dir_path ("
40 << context_->unpacked_dir_path.get()
41 << ") path does not exist";
42 return Step::Status::INVALID_VALUE;
45 if (!context_->manifest_data.get()) {
46 LOG(ERROR) << "manifest_data attribute is empty";
47 return Step::Status::MANIFEST_NOT_FOUND;
50 if (context_->pkgid.get().empty()) {
51 LOG(ERROR) << "pkgid attribute is empty";
52 return Step::Status::PACKAGE_NOT_FOUND;
55 return Step::Status::OK;
58 Step::Status StepCopy::process() {
59 bf::path install_path;
60 if (context_->storage.get() == Storage::EXTENDED) {
61 install_path = bf::path(GetExtendedRootAppPath(context_->uid.get())) /
62 context_->pkgid.get();
64 install_path = context_->GetPkgPath();
67 ci::RemoveRWDirectories(context_->unpacked_dir_path.get());
70 bf::create_directories(install_path.parent_path(), error);
72 LOG(ERROR) << "Cannot create directory: "
73 << install_path.parent_path().string();
74 return Step::Status::APP_DIR_ERROR;
76 if (!MoveDir(context_->unpacked_dir_path.get(), install_path,
77 FSFlag::FS_MERGE_SKIP)) {
78 LOG(ERROR) << "Cannot move widget directory to install path, from "
79 << context_->unpacked_dir_path.get() << " to " << install_path;
80 return Status::APP_DIR_ERROR;
82 LOG(INFO) << "Successfully move: " << context_->unpacked_dir_path.get()
83 << " to: " << install_path << " directory";
85 if (context_->storage.get() == Storage::EXTENDED) {
86 bf::create_symlink(install_path, context_->GetPkgPath(), error);
88 LOG(ERROR) << "Failed to create symlink for extended path: "
95 Step::Status StepCopy::clean() {
96 if (context_->external_storage)
97 context_->external_storage->Commit();
101 Step::Status StepCopy::undo() {
102 if (context_->external_storage) {
103 context_->external_storage->Abort();
104 } else if (context_->storage.get() == Storage::EXTENDED) {
105 bf::path install_path =
106 bf::path(GetExtendedRootAppPath(context_->uid.get())) /
107 context_->pkgid.get();
108 RemoveAll(install_path);
111 if (!RemoveAll(context_->GetPkgPath()))
112 return Status::APP_DIR_ERROR;
116 } // namespace filesystem
117 } // namespace common_installer