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 "step/mount/step_mount_install.h"
7 #include <boost/filesystem/operations.hpp>
8 #include <boost/filesystem/path.hpp>
12 #include "common/paths.h"
13 #include "common/request.h"
14 #include "common/tzip_interface.h"
15 #include "common/utils/file_util.h"
17 namespace bf = boost::filesystem;
18 namespace bs = boost::system;
20 namespace common_installer {
23 Step::Status StepMountInstall::process() {
24 context_->pkg_path.set(
25 context_->root_application_path.get() / context_->pkgid.get());
27 TzipInterface tzip_unpack(context_->unpacked_dir_path.get());
28 if (!tzip_unpack.UnmountZip()) {
29 LOG(ERROR) << "Failed to unmount zip package from temporary path";
30 return Status::APP_DIR_ERROR;
33 bf::path zip_destination_path =
34 GetZipPackageLocation(context_->pkg_path.get(), context_->pkgid.get());
35 if (!bf::exists(zip_destination_path.parent_path())) {
37 bf::create_directories(zip_destination_path.parent_path(), error);
39 LOG(ERROR) << "Failed to create diretory: "
40 << zip_destination_path.parent_path();
41 return Status::APP_DIR_ERROR;
45 if (!CopyFile(context_->file_path.get(), zip_destination_path)) {
46 return Status::APP_DIR_ERROR;
48 context_->manifest_data.get()->zip_mount_file =
49 strdup(zip_destination_path.c_str());
51 bf::path mount_point = GetMountLocation(context_->pkg_path.get());
52 TzipInterface tzip_final(mount_point);
53 if (!tzip_final.MountZip(zip_destination_path)) {
54 LOG(ERROR) << "Failed to mount zip package in installation path";
55 return Status::APP_DIR_ERROR;
58 LOG(INFO) << "Successfully mount zip package in: " << mount_point;
62 Step::Status StepMountInstall::clean() {
63 bf::path mount_point = GetMountLocation(context_->pkg_path.get());
64 TzipInterface tzip_final(mount_point);
65 if (!tzip_final.UnmountZip()) {
66 LOG(ERROR) << "Failed to unmount zip package after installation";
67 return Status::APP_DIR_ERROR;
73 Step::Status StepMountInstall::undo() {
75 bf::path mount_point = GetMountLocation(context_->pkg_path.get());
76 TzipInterface tzip_final(mount_point);
77 tzip_final.UnmountZip();
78 bf::remove(GetZipPackageLocation(context_->pkg_path.get(),
79 context_->pkgid.get()), error);
80 bf::remove(context_->pkg_path.get(), error);
82 LOG(ERROR) << "Failed to remove package content";
83 return Status::APP_DIR_ERROR;
88 Step::Status StepMountInstall::precheck() {
89 if (context_->root_application_path.get().empty()) {
90 LOG(ERROR) << "root_application_path attribute is empty";
91 return Step::Status::INVALID_VALUE;
93 if (!bf::exists(context_->root_application_path.get())) {
94 LOG(ERROR) << "root_application_path ("
95 << context_->root_application_path.get()
96 << ") path does not exist";
97 return Step::Status::INVALID_VALUE;
100 if (context_->unpacked_dir_path.get().empty()) {
101 LOG(ERROR) << "unpacked_dir_path attribute is empty";
102 return Step::Status::INVALID_VALUE;
104 if (!bf::exists(context_->unpacked_dir_path.get())) {
105 LOG(ERROR) << "unpacked_dir_path ("
106 << context_->unpacked_dir_path.get()
107 << ") path does not exist";
108 return Step::Status::INVALID_VALUE;
111 if (context_->pkgid.get().empty()) {
112 LOG(ERROR) << "pkgid attribute is empty";
113 return Step::Status::PACKAGE_NOT_FOUND;
116 return Step::Status::OK;
120 } // namespace common_installer