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_recover.h"
7 #include <pkgmgrinfo_basic.h>
11 #include "common/utils/file_util.h"
12 #include "common/utils/paths.h"
13 #include "common/tzip_interface.h"
14 #include "common/zip_interface.h"
16 namespace fs = std::filesystem;
18 namespace common_installer {
21 Step::Status StepMountRecover::RecoveryMountUpdate() {
22 fs::path zip_destination_path =
23 GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
24 manifest_x* manifest = context_->manifest_data.get();
26 manifest->zip_mount_file = strdup(zip_destination_path.c_str());
28 fs::path mount_point = GetMountLocation(context_->GetPkgPath());
29 auto zip_final = CreateZipInterface(mount_point);
30 if (!zip_final->MountZip(zip_destination_path)) {
31 LOG(ERROR) << "Failed to mount zip package in installation path";
32 return Status::APP_DIR_ERROR;
38 Step::Status StepMountRecover::Cleanup() {
39 recovery::RecoveryFile* recovery_file =
40 context_->recovery_info.get().recovery_file.get();
42 LOG(ERROR) << "Failed to get recovery info";
43 return Status::RECOVERY_ERROR;
46 if (recovery_file->type() != RequestType::MountUpdate)
49 fs::path zip_destination_path =
50 GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
51 fs::path backup_zip_location = GetBackupPathForZipFile(zip_destination_path);
53 if (fs::exists(backup_zip_location)) {
54 if (!Remove(backup_zip_location)) {
55 LOG(ERROR) << "Fail to remove backup zip location : "
56 << backup_zip_location;
57 return Status::RECOVERY_ERROR;
64 Step::Status StepMountRecover::clean() {
65 recovery::RecoveryFile* recovery_file =
66 context_->recovery_info.get().recovery_file.get();
68 LOG(ERROR) << "Failed to get recovery info";
69 return Status::RECOVERY_ERROR;
72 if (recovery_file->type() != RequestType::MountUpdate)
79 Step::Status StepMountRecover::undo() {
80 recovery::RecoveryFile* recovery_file =
81 context_->recovery_info.get().recovery_file.get();
83 LOG(ERROR) << "Failed to get recovery info";
84 return Status::RECOVERY_ERROR;
87 if (recovery_file->type() != RequestType::MountUpdate)
94 Step::Status StepMountRecover::UmountPackagePath() {
95 fs::path mount_point = GetMountLocation(context_->GetPkgPath());
96 auto zip_final = CreateZipInterface(mount_point);
97 if (!zip_final->UnmountZip()) {
98 LOG(ERROR) << "Failed to unmount zip package after installation";
99 return Status::APP_DIR_ERROR;
105 std::unique_ptr<IZipInterface> StepMountRecover::CreateZipInterface(
106 const std::filesystem::path& mount_path) {
107 std::unique_ptr<IZipInterface> zip_interface(
108 new TzipInterface(mount_path));
109 return zip_interface;
113 } // namespace common_installer