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/backup_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 if (!bf::exists(mount_point)) {
54 bf::create_directories(mount_point, error);
56 LOG(ERROR) << "Failed to create mount point directory: " << mount_point;
57 return Status::APP_DIR_ERROR;
60 TzipInterface tzip_final(mount_point);
61 if (!tzip_final.MountZip(zip_destination_path)) {
62 LOG(ERROR) << "Failed to mount zip package in installation path";
63 return Status::APP_DIR_ERROR;
66 LOG(INFO) << "Successfully mount zip package in: " << mount_point;
70 Step::Status StepMountInstall::clean() {
71 bf::path mount_point = GetMountLocation(context_->pkg_path.get());
72 TzipInterface tzip_final(mount_point);
73 if (!tzip_final.UnmountZip()) {
74 LOG(ERROR) << "Failed to unmount zip package after installation";
75 return Status::APP_DIR_ERROR;
78 bf::remove(mount_point, error);
82 Step::Status StepMountInstall::undo() {
84 bf::path mount_point = GetMountLocation(context_->pkg_path.get());
85 TzipInterface tzip_final(mount_point);
86 tzip_final.UnmountZip();
87 bf::remove(GetZipPackageLocation(context_->pkg_path.get(),
88 context_->pkgid.get()), error);
89 bf::remove(context_->pkg_path.get(), error);
91 LOG(ERROR) << "Failed to remove package content";
92 return Status::APP_DIR_ERROR;
97 Step::Status StepMountInstall::precheck() {
98 if (context_->root_application_path.get().empty()) {
99 LOG(ERROR) << "root_application_path attribute is empty";
100 return Step::Status::INVALID_VALUE;
102 if (!bf::exists(context_->root_application_path.get())) {
103 LOG(ERROR) << "root_application_path ("
104 << context_->root_application_path.get()
105 << ") path does not exist";
106 return Step::Status::INVALID_VALUE;
109 if (context_->unpacked_dir_path.get().empty()) {
110 LOG(ERROR) << "unpacked_dir_path attribute is empty";
111 return Step::Status::INVALID_VALUE;
113 if (!bf::exists(context_->unpacked_dir_path.get())) {
114 LOG(ERROR) << "unpacked_dir_path ("
115 << context_->unpacked_dir_path.get()
116 << ") path does not exist";
117 return Step::Status::INVALID_VALUE;
120 if (context_->pkgid.get().empty()) {
121 LOG(ERROR) << "pkgid attribute is empty";
122 return Step::Status::PACKAGE_NOT_FOUND;
125 return Step::Status::OK;
129 } // namespace common_installer