Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / step / filesystem / step_recover_manifest.cc
1 // Copyright (c) 2015 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.
4
5 #include "common/step/filesystem/step_recover_manifest.h"
6
7 #include <pkgmgr-info.h>
8
9 #include <filesystem>
10
11 #include "common/utils/paths.h"
12 #include "common/utils/file_util.h"
13
14 namespace fs = std::filesystem;
15
16 namespace common_installer {
17 namespace filesystem {
18
19 Step::Status StepRecoverManifest::RecoveryNew() {
20   if (!SetXmlPaths(context_->is_readonly_package.get())) {
21     LOG(DEBUG) << "Manifest recovery not needed";
22     return Status::OK;
23   }
24   Remove(context_->xml_path.get());
25   LOG(INFO) << "Manifest recovery done";
26   return Status::OK;
27 }
28
29 Step::Status StepRecoverManifest::RecoveryUpdate() {
30   if (!SetXmlPaths(context_->is_readonly_package.get())) {
31     LOG(DEBUG) << "Manifest recovery not needed";
32     return Status::OK;
33   }
34   if (fs::exists(context_->backup_xml_path.get())) {
35     if (!Remove(context_->xml_path.get())) {
36       LOG(ERROR) << "Cannot move manifest file to restore its location";
37       return Status::RECOVERY_ERROR;
38     }
39     (void) MoveFile(context_->backup_xml_path.get(), context_->xml_path.get());
40   }
41   LOG(INFO) << "Manifest recovery done";
42   return Status::OK;
43 }
44
45 Step::Status StepRecoverManifest::RecoveryReadonlyUpdateInstall() {
46   if (!SetXmlPaths(false)) {
47     LOG(DEBUG) << "Manifest recovery not needed";
48     return Status::OK;
49   }
50   if (fs::exists(context_->xml_path.get())) {
51     if (!Remove(context_->xml_path.get())) {
52       LOG(ERROR) << "Cannot move manifest file to restore its location";
53       return Status::RECOVERY_ERROR;
54     }
55   }
56   LOG(INFO) << "Manifest recovery done";
57   return Status::OK;
58 }
59
60 Step::Status StepRecoverManifest::Cleanup() {
61   if (!SetXmlPaths(context_->is_readonly_package.get())) {
62     LOG(DEBUG) << "Manifest recovery not needed";
63     return Status::OK;
64   }
65   if (fs::exists(context_->backup_xml_path.get())) {
66     if (!Remove(context_->backup_xml_path.get())) {
67       LOG(ERROR) << "Cannot remove backup manifest file";
68       return Status::RECOVERY_ERROR;
69     }
70   }
71   LOG(INFO) << "Manifest recovery done";
72   return Status::OK;
73 }
74
75 bool StepRecoverManifest::SetXmlPaths(bool is_readonly_package) {
76   if (context_->pkgid.get().empty())
77     return false;
78   fs::path xml_path =
79       fs::path(getUserManifestPath(context_->uid.get(), is_readonly_package))
80       / context_->pkgid.get();
81   xml_path += ".xml";
82   context_->xml_path.set(xml_path);
83   context_->backup_xml_path.set(GetBackupPathForManifestFile(xml_path));
84   return true;
85 }
86
87 }  // namespace filesystem
88 }  // namespace common_installer