Fix namespace of StepCreateRecoveryFile
[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 <boost/filesystem/path.hpp>
8
9 #include <pkgmgr-info.h>
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include <unistd.h>
13 #include <tzplatform_config.h>
14
15 #include <memory>
16 #include <string>
17 #include <utility>
18
19 #include "common/pkgmgr_query.h"
20 #include "common/request.h"
21 #include "common/utils/file_util.h"
22 #include "common/utils/user_util.h"
23 #include "common/recovery_file.h"
24
25 namespace bf = boost::filesystem;
26
27 namespace common_installer {
28 namespace recovery {
29
30 Step::Status StepCreateRecoveryFile::process() {
31   std::string recovery_filename = context_->pkg_type.get() + "-recovery";
32   bf::path recovery_filepath = GenerateTemporaryPath(
33       context_->root_application_path.get() / recovery_filename);
34   auto recovery_file =
35       recovery::RecoveryFile::CreateRecoveryFile(recovery_filepath,
36           context_->request_type.get());
37   if (!recovery_file) {
38     LOG(ERROR) << "Failed to create recovery file";
39     return Status::CONFIG_ERROR;
40   }
41   context_->recovery_info.set(RecoveryInfo(std::move(recovery_file)));
42
43   return Status::OK;
44 }
45
46 Step::Status StepCreateRecoveryFile::precheck() {
47   if (context_->pkg_type.get().empty()) {
48     LOG(ERROR) << "Pkg type is not set";
49     return Status::INVALID_VALUE;
50   }
51   if (context_->root_application_path.get().empty()) {
52     LOG(ERROR) << "Root application path is not set";
53     return Status::INVALID_VALUE;
54   }
55   return Status::OK;
56 }
57
58 Step::Status StepCreateRecoveryFile::clean() {
59   // Clean up operations should not be covered by recovery
60   // as backup information is being lost during clean up
61   context_->recovery_info.get().recovery_file.reset();
62   return Status::OK;
63 }
64
65
66 }  // namespace recovery
67 }  // namespace common_installer