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.
5 #include "common/step/filesystem/step_recover_manifest.h"
7 #include <pkgmgr-info.h>
11 #include "common/utils/paths.h"
12 #include "common/utils/file_util.h"
14 namespace fs = std::filesystem;
16 namespace common_installer {
17 namespace filesystem {
19 Step::Status StepRecoverManifest::RecoveryNew() {
20 if (!SetXmlPaths(context_->is_readonly_package.get())) {
21 LOG(DEBUG) << "Manifest recovery not needed";
24 Remove(context_->xml_path.get());
25 LOG(INFO) << "Manifest recovery done";
29 Step::Status StepRecoverManifest::RecoveryUpdate() {
30 if (!SetXmlPaths(context_->is_readonly_package.get())) {
31 LOG(DEBUG) << "Manifest recovery not needed";
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;
39 (void) MoveFile(context_->backup_xml_path.get(), context_->xml_path.get());
41 LOG(INFO) << "Manifest recovery done";
45 Step::Status StepRecoverManifest::RecoveryReadonlyUpdateInstall() {
46 if (!SetXmlPaths(false)) {
47 LOG(DEBUG) << "Manifest recovery not needed";
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;
56 LOG(INFO) << "Manifest recovery done";
60 Step::Status StepRecoverManifest::Cleanup() {
61 if (!SetXmlPaths(context_->is_readonly_package.get())) {
62 LOG(DEBUG) << "Manifest recovery not needed";
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;
71 LOG(INFO) << "Manifest recovery done";
75 bool StepRecoverManifest::SetXmlPaths(bool is_readonly_package) {
76 if (context_->pkgid.get().empty())
79 fs::path(getUserManifestPath(context_->uid.get(), is_readonly_package))
80 / context_->pkgid.get();
82 context_->xml_path.set(xml_path);
83 context_->backup_xml_path.set(GetBackupPathForManifestFile(xml_path));
87 } // namespace filesystem
88 } // namespace common_installer