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 <boost/filesystem/path.hpp>
8 #include <boost/filesystem/operations.hpp>
10 #include <pkgmgrinfo_basic.h>
12 #include "common/utils/file_util.h"
13 #include "common/utils/paths.h"
14 #include "common/tzip_interface.h"
15 #include "common/zip_interface.h"
17 namespace bf = boost::filesystem;
19 namespace common_installer {
22 Step::Status StepMountRecover::RecoveryMountUpdate() {
23 bf::path zip_destination_path =
24 GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
25 manifest_x* manifest = context_->manifest_data.get();
27 manifest->zip_mount_file = strdup(zip_destination_path.c_str());
29 bf::path mount_point = GetMountLocation(context_->GetPkgPath());
30 auto zip_final = CreateZipInterface(mount_point);
31 if (!zip_final->MountZip(zip_destination_path)) {
32 LOG(ERROR) << "Failed to mount zip package in installation path";
33 return Status::APP_DIR_ERROR;
39 Step::Status StepMountRecover::Cleanup() {
40 recovery::RecoveryFile* recovery_file =
41 context_->recovery_info.get().recovery_file.get();
43 LOG(ERROR) << "Failed to get recovery info";
44 return Status::RECOVERY_ERROR;
47 if (recovery_file->type() != RequestType::MountUpdate)
50 bf::path zip_destination_path =
51 GetZipPackageLocation(context_->GetPkgPath(), context_->pkgid.get());
52 bf::path backup_zip_location = GetBackupPathForZipFile(zip_destination_path);
54 if (bf::exists(backup_zip_location)) {
55 if (!Remove(backup_zip_location)) {
56 LOG(ERROR) << "Fail to remove backup zip location : "
57 << backup_zip_location;
58 return Status::RECOVERY_ERROR;
65 Step::Status StepMountRecover::clean() {
66 recovery::RecoveryFile* recovery_file =
67 context_->recovery_info.get().recovery_file.get();
69 LOG(ERROR) << "Failed to get recovery info";
70 return Status::RECOVERY_ERROR;
73 if (recovery_file->type() != RequestType::MountUpdate)
80 Step::Status StepMountRecover::undo() {
81 recovery::RecoveryFile* recovery_file =
82 context_->recovery_info.get().recovery_file.get();
84 LOG(ERROR) << "Failed to get recovery info";
85 return Status::RECOVERY_ERROR;
88 if (recovery_file->type() != RequestType::MountUpdate)
95 Step::Status StepMountRecover::UmountPackagePath() {
96 bf::path mount_point = GetMountLocation(context_->GetPkgPath());
97 auto zip_final = CreateZipInterface(mount_point);
98 if (!zip_final->UnmountZip()) {
99 LOG(ERROR) << "Failed to unmount zip package after installation";
100 return Status::APP_DIR_ERROR;
106 std::unique_ptr<IZipInterface> StepMountRecover::CreateZipInterface(
107 const boost::filesystem::path& mount_path) {
108 std::unique_ptr<IZipInterface> zip_interface(
109 new TzipInterface(mount_path));
110 return zip_interface;
114 } // namespace common_installer