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/paths.h"
13 #include "common/tzip_interface.h"
14 #include "common/zip_interface.h"
16 namespace bf = boost::filesystem;
18 namespace common_installer {
21 Step::Status StepMountRecover::RecoveryMountUpdate() {
22 bf::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 bf::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::clean() {
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)
53 Step::Status StepMountRecover::undo() {
54 recovery::RecoveryFile* recovery_file =
55 context_->recovery_info.get().recovery_file.get();
57 LOG(ERROR) << "Failed to get recovery info";
58 return Status::RECOVERY_ERROR;
61 if (recovery_file->type() != RequestType::MountUpdate)
68 Step::Status StepMountRecover::UmountPackagePath() {
69 bf::path mount_point = GetMountLocation(context_->GetPkgPath());
70 auto zip_final = CreateZipInterface(mount_point);
71 if (!zip_final->UnmountZip()) {
72 LOG(ERROR) << "Failed to unmount zip package after installation";
73 return Status::APP_DIR_ERROR;
79 std::unique_ptr<IZipInterface> StepMountRecover::CreateZipInterface(
80 const boost::filesystem::path& mount_path) {
81 std::unique_ptr<IZipInterface> zip_interface(
82 new TzipInterface(mount_path));
87 } // namespace common_installer