1 // Copyright (c) 2015 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/backup/step_backup_manifest.h"
7 #include <pkgmgr-info.h>
8 #include <pkgmgr_installer.h>
13 #include <system_error>
15 #include "common/utils/paths.h"
16 #include "common/utils/file_util.h"
18 namespace ci = common_installer;
19 namespace fs = std::filesystem;
21 namespace common_installer {
24 Step::Status StepBackupManifest::precheck() {
25 if (!fs::exists(context_->xml_path.get())) {
26 LOG(ERROR) << "Xml manifest file does not exist";
27 return Status::MANIFEST_NOT_FOUND;
33 Step::Status StepBackupManifest::process() {
34 // set backup file path
35 fs::path backup_xml_path =
36 GetBackupPathForManifestFile(context_->xml_path.get());
37 context_->backup_xml_path.set(backup_xml_path);
38 if (!MoveFile(context_->xml_path.get(), backup_xml_path, true) ||
39 !CopyFile(backup_xml_path, context_->xml_path.get())) {
40 LOG(ERROR) << "Failed to make a copy of xml manifest file";
41 return Status::MANIFEST_ERROR;
44 LOG(DEBUG) << "Manifest backup created";
48 Step::Status StepBackupManifest::clean() {
49 LOG(DEBUG) << "Remove manifest backup";
50 ci::Remove(context_->backup_xml_path.get());
55 Step::Status StepBackupManifest::undo() {
56 if (!fs::exists(context_->backup_xml_path.get()))
59 std::error_code error;
60 fs::remove(context_->xml_path.get(), error);
62 LOG(ERROR) << "Failed to remove newly generated xml file in revert";
63 return Status::MANIFEST_ERROR;
65 if (!MoveFile(context_->backup_xml_path.get(),
66 context_->xml_path.get())) {
67 LOG(ERROR) << "Failed to revert a content of xml manifest file";
68 return Status::MANIFEST_ERROR;
70 LOG(DEBUG) << "Manifest reverted from backup";
76 } // namespace common_installer