1 // Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
5 #include "common/step/recovery/step_create_recovery_file.h"
7 #include <pkgmgr-info.h>
11 #include <tzplatform_config.h>
18 #include "common/utils/pkgmgr_query.h"
19 #include "common/utils/file_util.h"
20 #include "common/utils/user_util.h"
21 #include "common/utils/request.h"
22 #include "common/recovery_file.h"
24 namespace fs = std::filesystem;
26 namespace common_installer {
29 Step::Status StepCreateRecoveryFile::process() {
30 fs::path recovery_filename = context_->recovery_info.get().filepath;
32 if (recovery_filename.empty()) {
33 std::string file_format = context_->pkg_type.get() + "-recovery";
34 recovery_filename = GenerateTemporaryPath(
35 context_->root_application_path.get() / file_format);
39 recovery::RecoveryFile::CreateRecoveryFile(recovery_filename,
40 context_->request_type.get());
42 LOG(ERROR) << "Failed to create recovery file";
43 return Status::CONFIG_ERROR;
46 if (context_->recovery_info.get().filepath.empty())
47 context_->recovery_info.set(RecoveryInfo(std::move(recovery_file)));
49 context_->recovery_info.get().recovery_file = std::move(recovery_file);
54 Step::Status StepCreateRecoveryFile::precheck() {
55 if (context_->pkg_type.get().empty()) {
56 LOG(ERROR) << "Pkg type is not set";
57 return Status::INVALID_VALUE;
59 if (context_->root_application_path.get().empty()) {
60 LOG(ERROR) << "Root application path is not set";
61 return Status::INVALID_VALUE;
66 Step::Status StepCreateRecoveryFile::clean() {
67 // Clean up operations should not be covered by recovery
68 // as backup information is being lost during clean up
69 context_->recovery_info.get().recovery_file.reset();
74 } // namespace recovery
75 } // namespace common_installer