[Recovery] StepRecoveryApplication 14/45714/3
authorWojciech Kosowicz <w.kosowicz@samsung.com>
Tue, 4 Aug 2015 10:11:29 +0000 (12:11 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 11 Aug 2015 08:39:37 +0000 (01:39 -0700)
Change-Id: I3999889e1d790095c1cd93282b823ea1ae2ca6b2

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

index 338d845..d3c22d4 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_application.cc
   step/step_recover_files.cc
   step/step_recover_icons.cc
   step/step_recover_manifest.cc
diff --git a/src/common/step/step_recover_application.cc b/src/common/step/step_recover_application.cc
new file mode 100644 (file)
index 0000000..2be4f07
--- /dev/null
@@ -0,0 +1,56 @@
+// 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_application.h"
+
+#include <boost/filesystem.hpp>
+
+#include "common/pkgmgr_registration.h"
+
+namespace bf = boost::filesystem;
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepRecoverApplication::RecoveryNew() {
+  if (!SetXmlPaths())
+    return Status::OK;
+  UnregisterAppInPkgmgr(context_->xml_path.get(), context_->pkgid.get(),
+                        context_->uid.get());
+  return Status::OK;
+}
+
+Step::Status StepRecoverApplication::RecoveryUpdate() {
+  if (!SetXmlPaths()) {
+    LOG(ERROR) << "Some parameters are lacking";
+    return Status::ERROR;
+  }
+  bf::path xml_path = bf::exists(context_->backup_xml_path.get()) ?
+        context_->backup_xml_path.get() : context_->xml_path.get();
+  UnregisterAppInPkgmgr(xml_path, context_->pkgid.get(),
+                        context_->uid.get());
+  if (!RegisterAppInPkgmgr(xml_path,
+                           context_->pkgid.get().c_str(),
+                           context_->certificate_info.get(),
+                           context_->uid.get())) {
+    LOG(ERROR) << "Unsuccessful app registration";
+    return Status::ERROR;
+  }
+  return Status::OK;
+}
+
+bool StepRecoverApplication::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 pkgmgr
+}  // namespace common_installer
diff --git a/src/common/step/step_recover_application.h b/src/common/step/step_recover_application.h
new file mode 100644 (file)
index 0000000..785fbd4
--- /dev/null
@@ -0,0 +1,35 @@
+// 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_APPLICATION_H_
+#define COMMON_STEP_STEP_RECOVER_APPLICATION_H_
+
+#include "common/context_installer.h"
+#include "common/step/step_recovery.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+/**
+ * @brief recovers applications entries in pkgmgr
+ *
+ * Part of RecoveryMode. In case of partial installation
+ * app get unregistered with pkgmgr. In case of unsuccessful
+ * update app in state before update gets re-registered
+ */
+class StepRecoverApplication : public recovery::StepRecovery {
+ public:
+  using StepRecovery::StepRecovery;
+  Status RecoveryNew() override;
+  Status RecoveryUpdate() override;
+ private:
+  bool SetXmlPaths();
+
+  SCOPE_LOG_TAG(RecoverApplication)
+};
+
+}  // namespace pkgmgr
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_STEP_RECOVER_APPLICATION_H_