Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / recovery / step_create_recovery_file.cc
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.
4
5 #include "common/step/recovery/step_create_recovery_file.h"
6
7 #include <pkgmgr-info.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11 #include <tzplatform_config.h>
12
13 #include <filesystem>
14 #include <memory>
15 #include <string>
16 #include <utility>
17
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"
23
24 namespace fs = std::filesystem;
25
26 namespace common_installer {
27 namespace recovery {
28
29 Step::Status StepCreateRecoveryFile::process() {
30   fs::path recovery_filename = context_->recovery_info.get().filepath;
31
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);
36   }
37
38   auto recovery_file =
39     recovery::RecoveryFile::CreateRecoveryFile(recovery_filename,
40         context_->request_type.get());
41   if (!recovery_file) {
42     LOG(ERROR) << "Failed to create recovery file";
43     return Status::CONFIG_ERROR;
44   }
45
46   if (context_->recovery_info.get().filepath.empty())
47     context_->recovery_info.set(RecoveryInfo(std::move(recovery_file)));
48   else
49     context_->recovery_info.get().recovery_file = std::move(recovery_file);
50
51   return Status::OK;
52 }
53
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;
58   }
59   if (context_->root_application_path.get().empty()) {
60     LOG(ERROR) << "Root application path is not set";
61     return Status::INVALID_VALUE;
62   }
63   return Status::OK;
64 }
65
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();
70   return Status::OK;
71 }
72
73
74 }  // namespace recovery
75 }  // namespace common_installer