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 "common/step/mount/step_mount_unpacked.h"
12 #include "common/utils/paths.h"
13 #include "common/utils/file_util.h"
14 #include "common/tzip_interface.h"
15 #include "common/zip_interface.h"
17 namespace fs = std::filesystem;
21 const char kPackageUnpackDirPath[] = UNPACKDIR;
25 namespace common_installer {
28 Step::Status StepMountUnpacked::process() {
29 fs::path tmp_dir = GenerateTmpDir(kPackageUnpackDirPath);
30 context_->unpacked_dir_path.set(tmp_dir);
31 // write unpacked directory for recovery file
32 // to remove unpacked dir properly when recovery mode
33 if (context_->recovery_info.get().recovery_file) {
34 context_->recovery_info.get().recovery_file->set_unpacked_dir(tmp_dir);
35 context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
38 auto zip = CreateZipInterface(context_->unpacked_dir_path.get());
39 if (!zip->MountZip(context_->file_path.get())) {
40 LOG(ERROR) << "Failed to mount zip file: " << context_->file_path.get();
41 return Status::IMAGE_ERROR;
43 LOG(DEBUG) << "Zip mounted in unpacked_dir: "
44 << context_->unpacked_dir_path.get();
48 Step::Status StepMountUnpacked::undo() {
49 auto zip = CreateZipInterface(context_->unpacked_dir_path.get());
50 if (!zip->UnmountZip()) {
51 LOG(ERROR) << "Failed to unmount zip file: " << context_->file_path.get();
52 return Status::IMAGE_ERROR;
55 RemoveAll(context_->unpacked_dir_path.get());
57 if (context_->request_type.get() == RequestType::MountUpdate) {
58 fs::path mount_point = GetMountLocation(context_->GetPkgPath());
59 auto zip_final = CreateZipInterface(mount_point);
60 if (!zip_final->UnmountZip()) {
61 LOG(ERROR) << "Failed to unmount zip package after revoke";
62 return Status::APP_DIR_ERROR;
68 Step::Status StepMountUnpacked::precheck() {
69 if (context_->file_path.get().empty()) {
70 LOG(ERROR) << "file_path attribute is empty";
71 return Step::Status::INVALID_VALUE;
73 if (!fs::exists(context_->file_path.get())) {
74 LOG(ERROR) << "file_path ("
75 << context_->file_path.get()
76 << ") path does not exist";
77 return Step::Status::INVALID_VALUE;
79 if (context_->root_application_path.get().empty()) {
80 LOG(ERROR) << "root_application_path attribute is empty";
81 return Step::Status::INVALID_VALUE;
83 if (!fs::exists(context_->root_application_path.get())) {
84 LOG(ERROR) << "root_application_path ("
85 << context_->root_application_path.get()
86 << ") path does not exist";
87 return Step::Status::INVALID_VALUE;
92 std::unique_ptr<IZipInterface> StepMountUnpacked::CreateZipInterface(
93 const fs::path& mount_path) {
94 std::unique_ptr<IZipInterface> zip_interface(
95 new TzipInterface(mount_path));
100 } // namespace common_installer