[Recovery] StepRecoverManifest 04/45704/4
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 3 Aug 2015 13:56:15 +0000 (15:56 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 11 Aug 2015 08:26:47 +0000 (01:26 -0700)
Change-Id: I21c480d113ddf6211ad25298c5753f9f5f57f71a

src/common/CMakeLists.txt
src/common/step/step_open_recovery_file.cc
src/common/step/step_recover_manifest.cc [new file with mode: 0644]
src/common/step/step_recover_manifest.h [new file with mode: 0644]

index 61569e9..4c382df 100644 (file)
@@ -19,6 +19,7 @@ SET(SRCS
   step/step_copy_storage_directories.cc
   step/step_create_storage_directories.cc
   step/step_generate_xml.cc
+  step/step_recover_manifest.cc
   step/step_recovery.cc
   step/step_register_app.cc
   step/step_old_manifest.cc
index 46596c9..c6a16be 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "common/step/step_open_recovery_file.h"
 
+#include <cassert>
+
 #include "common/recovery_file.h"
 
 namespace common_installer {
diff --git a/src/common/step/step_recover_manifest.cc b/src/common/step/step_recover_manifest.cc
new file mode 100644 (file)
index 0000000..4b2506b
--- /dev/null
@@ -0,0 +1,66 @@
+// 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
diff --git a/src/common/step/step_recover_manifest.h b/src/common/step/step_recover_manifest.h
new file mode 100644 (file)
index 0000000..467cb88
--- /dev/null
@@ -0,0 +1,39 @@
+// 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_