--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_backup_manifest.h"
+
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <pkgmgr-info.h>
+#include <pkgmgr_installer.h>
+
+#include <string>
+
+#include "utils/file_util.h"
+#include "utils/logging.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace common_installer {
+namespace backup_manifest {
+
+Step::Status StepBackupManifest::precheck() {
+ if (!bf::exists(context_->xml_path.get())) {
+ LOG(ERROR) << "Xml manifest file does not exist";
+ return Status::ERROR;
+ }
+}
+
+Step::Status StepBackupManifest::process() {
+ // set backup file path
+ bf::path backup_xml_path = context_->xml_path.get();
+ backup_xml_path = + ".bck";
+ context_->backup_xml_path.set(backup_xml_path);
+
+ if (!utils::MoveFile(context_->xml_path.get(),
+ context_->backup_xml_path.get())) {
+ LOG(ERROR) << "Failed to make a copy of xml manifest file";
+ return Status::ERROR;
+ }
+ LOG(DEBUG) << "Manifest backup created";
+ return Status::OK;
+}
+
+Step::Status StepBackupManifest::clean() {
+ bs::error_code error;
+ bf::remove(context_->backup_xml_path.get(), error);
+ if (error) {
+ LOG(WARNING) << "Cannot remove backup manifest file";
+ return Status::ERROR;
+ }
+ LOG(DEBUG) << "Manifest backup removed";
+ return Status::OK;
+}
+
+Step::Status StepBackupManifest::undo() {
+ if (bf::exists(context_->backup_xml_path.get())) {
+ bs::error_code error;
+ bf::remove(context_->xml_path.get(), error);
+ if (error) {
+ LOG(ERROR) << "Failed to remove newly generated xml file in revert";
+ return Status::ERROR;
+ }
+ if (!utils::MoveFile(context_->backup_xml_path.get(),
+ context_->xml_path.get())) {
+ LOG(ERROR) << "Failed to revert a content of xml manifest file";
+ return Status::ERROR;
+ }
+ LOG(DEBUG) << "Manifest reverted from backup";
+ }
+ return Status::OK;
+}
+
+} // namespace backup_manifest
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_BACKUP_MANIFEST_H_
+#define COMMON_STEP_STEP_BACKUP_MANIFEST_H_
+
+#include "common/context_installer.h"
+#include "common/step/step.h"
+#include "utils/logging.h"
+
+namespace common_installer {
+namespace backup_manifest {
+
+class StepBackupManifest : public Step {
+ public:
+ using Step::Step;
+
+ Status process() override;
+ Status clean() override;
+ Status undo() override;
+ Status precheck() override;
+
+ SCOPE_LOG_TAG(BackupManifest)
+};
+
+} // namespace backup_manifest
+} // namespace common_installer
+
+#endif // COMMON_STEP_STEP_BACKUP_MANIFEST_H_