--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/step/step_recover_manifest.h"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/system/error_code.hpp>
+#include <pkgmgr-info.h>
+
+#include "common/utils/file_util.h"
+
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace common_installer {
+namespace filesystem {
+
+Step::Status StepRecoverManifest::RecoveryNew() {
+ if (!SetXmlPaths()) {
+ LOG(DEBUG) << "Manifest recovery not needed";
+ return Status::OK;
+ }
+ if (bf::exists(context_->xml_path.get())) {
+ bs::error_code error;
+ bf::remove(context_->xml_path.get(), error);
+ }
+ LOG(INFO) << "Manifest recovery done";
+ return Status::OK;
+}
+
+Step::Status StepRecoverManifest::RecoveryUpdate() {
+ if (!SetXmlPaths()) {
+ LOG(DEBUG) << "Manifest recovery not needed";
+ return Status::OK;
+ }
+ if (bf::exists(context_->backup_xml_path.get())) {
+ if (bf::exists(context_->xml_path.get())) {
+ bs::error_code error;
+ bf::remove(context_->xml_path.get(), error);
+ if (error) {
+ LOG(ERROR) << "Cannot move manifest file to restore its location";
+ return Status::ERROR;
+ }
+ }
+ (void) MoveFile(context_->backup_xml_path.get(), context_->xml_path.get());
+ }
+ LOG(INFO) << "Manifest recovery done";
+ return Status::OK;
+}
+
+bool StepRecoverManifest::SetXmlPaths() {
+ if (context_->pkgid.get().empty())
+ return false;
+ bf::path xml_path = bf::path(getUserManifestPath(context_->uid.get()))
+ / context_->pkgid.get();
+ xml_path += ".xml";
+ context_->xml_path.set(xml_path);
+ xml_path += ".bck";
+ context_->backup_xml_path.set(xml_path);
+ return true;
+}
+
+} // namespace filesystem
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_STEP_STEP_RECOVER_MANIFEST_H_
+#define COMMON_STEP_STEP_RECOVER_MANIFEST_H_
+
+#include "common/context_installer.h"
+#include "common/step/step_recovery.h"
+#include "common/utils/logging.h"
+
+namespace common_installer {
+namespace filesystem {
+
+/**
+ * @brief The StepRecoverManifest class
+ * Fixes state of platform manfiest file in recovery mode.
+ *
+ * For recovering new installation, manifest file is removed.
+ * For recovering update installation, the old manifest of package is restored
+ * to its location.
+ */
+class StepRecoverManifest : public recovery::StepRecovery {
+ public:
+ using StepRecovery::StepRecovery;
+
+ Status RecoveryNew() override;
+ Status RecoveryUpdate() override;
+
+ private:
+ bool SetXmlPaths();
+
+ SCOPE_LOG_TAG(RecoverManifest)
+};
+
+} // namespace filesystem
+} // namespace common_installer
+
+#endif // COMMON_STEP_STEP_RECOVER_MANIFEST_H_