Supplement ParserPlugin 62/178962/14
authorJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 15 May 2018 04:52:06 +0000 (13:52 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Tue, 5 Jun 2018 05:40:45 +0000 (14:40 +0900)
- Add StepRecoverParserPlugin to provide recovery interface.
- Add clean / undo interface.
- Change StepRemoveManifest to remove manifest file at cleanup time.
- StepUnregisterApp will not remove modified manifest file.

Change-Id: I296bf6acfd5dbd2281e9eefb093e89688b2d9b15
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/plugins/plugin.h
src/common/plugins/types/category_plugin.cc
src/common/plugins/types/metadata_plugin.cc
src/common/plugins/types/tag_plugin.cc
src/common/step/pkgmgr/step_recover_parser_plugins.cc [new file with mode: 0644]
src/common/step/pkgmgr/step_recover_parser_plugins.h [new file with mode: 0644]
src/common/step/pkgmgr/step_remove_manifest.cc
src/common/step/pkgmgr/step_remove_manifest.h
src/common/step/pkgmgr/step_run_parser_plugins.cc
src/common/step/pkgmgr/step_run_parser_plugins.h
src/common/step/pkgmgr/step_unregister_app.cc

index 151f256..2784079 100644 (file)
@@ -26,7 +26,17 @@ namespace common_installer {
  */
 class Plugin {
  public:
-  enum class ActionType { Install, Upgrade, Uninstall };
+  enum class ActionType {
+      Unknown,
+      Install,
+      Upgrade,
+      Clean,
+      Undo,
+      Uninstall,
+      RecoverInstall,
+      RecoverUpgrade,
+      RecoverUninstall
+  };
   enum class ProcessType { Pre, Main, Post };
 
   virtual ~Plugin();
index d6c7a18..1243964 100644 (file)
@@ -41,6 +41,11 @@ std::string CategoryPlugin::GetFunctionName(ActionType action) const {
     {ActionType::Install,  "PKGMGR_CATEGORY_PARSER_PLUGIN_INSTALL"},
     {ActionType::Upgrade,  "PKGMGR_CATEGORY_PARSER_PLUGIN_UPGRADE"},
     {ActionType::Uninstall,  "PKGMGR_CATEGORY_PARSER_PLUGIN_UNINSTALL"},
+    {ActionType::RecoverInstall, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERINSTALL"},   // NOLINT
+    {ActionType::RecoverUpgrade, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERUPGRADE"},   // NOLINT
+    {ActionType::RecoverUninstall, "PKGMGR_CATEGORY_PARSER_PLUGIN_RECOVERUNINSTALL"},   // NOLINT
+    {ActionType::Clean, "PKGMGR_CATEGORY_PARSER_PLUGIN_CLEAN"},
+    {ActionType::Undo, "PKGMGR_CATEGORY_PARSER_PLUGIN_UNDO"},
   };
 
   auto pos = names.find(action);
index 1ea1699..aef5df1 100644 (file)
@@ -44,6 +44,11 @@ std::string MetadataPlugin::GetFunctionName(ActionType action) const {
     {ActionType::Install,  "PKGMGR_MDPARSER_PLUGIN_INSTALL"},
     {ActionType::Upgrade,  "PKGMGR_MDPARSER_PLUGIN_UPGRADE"},
     {ActionType::Uninstall,  "PKGMGR_MDPARSER_PLUGIN_UNINSTALL"},
+    {ActionType::RecoverInstall,  "PKGMGR_MDPARSER_PLUGIN_RECOVERINSTALL"},
+    {ActionType::RecoverUpgrade,  "PKGMGR_MDPARSER_PLUGIN_RECOVERUPGRADE"},
+    {ActionType::RecoverUninstall,  "PKGMGR_MDPARSER_PLUGIN_RECOVERUNINSTALL"},
+    {ActionType::Clean, "PKGMGR_MDPARSER_PLUGIN_CLEAN"},
+    {ActionType::Undo, "PKGMGR_MDPARSER_PLUGIN_UNDO"},
   };
 
   auto pos = names.find(action);
index 7734312..41caa9b 100644 (file)
@@ -24,12 +24,23 @@ std::string TagPlugin::GetFunctionName(ProcessType process,
     {{ActionType::Install,   ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_INSTALL"},   // NOLINT
     {{ActionType::Upgrade,   ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE"},   // NOLINT
     {{ActionType::Uninstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL"}, // NOLINT
+    {{ActionType::RecoverInstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERINSTALL"}, // NOLINT
+    {{ActionType::RecoverUpgrade, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERUPGRADE"}, // NOLINT
+    {{ActionType::RecoverUninstall, ProcessType::Pre},  "PKGMGR_PARSER_PLUGIN_PRE_RECOVERUNINSTALL"}, // NOLINT
     {{ActionType::Install,   ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_INSTALL"},       // NOLINT
     {{ActionType::Upgrade,   ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_UPGRADE"},       // NOLINT
     {{ActionType::Uninstall, ProcessType::Main}, "PKGMGR_PARSER_PLUGIN_UNINSTALL"},     // NOLINT
+    {{ActionType::RecoverInstall, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERINSTALL"}, // NOLINT
+    {{ActionType::RecoverUpgrade, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERUPGRADE"}, // NOLINT
+    {{ActionType::RecoverUninstall, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_RECOVERUNINSTALL"}, // NOLINT
+    {{ActionType::Clean, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_CLEAN"}, // NOLINT
+    {{ActionType::Undo, ProcessType::Main},  "PKGMGR_PARSER_PLUGIN_UNDO"}, // NOLINT
     {{ActionType::Install,   ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_INSTALL"},  // NOLINT
     {{ActionType::Upgrade,   ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_UPGRADE"},  // NOLINT
-    {{ActionType::Uninstall, ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL"} // NOLINT
+    {{ActionType::Uninstall, ProcessType::Post}, "PKGMGR_PARSER_PLUGIN_POST_UNINSTALL"}, // NOLINT
+    {{ActionType::RecoverInstall, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERINSTALL"}, // NOLINT
+    {{ActionType::RecoverUpgrade, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERUPGRADE"}, // NOLINT
+    {{ActionType::RecoverUninstall, ProcessType::Post},  "PKGMGR_PARSER_PLUGIN_POST_RECOVERUNINSTALL"}, // NOLINT
   };
 
   auto pos = names.find(std::make_pair(action, process));
diff --git a/src/common/step/pkgmgr/step_recover_parser_plugins.cc b/src/common/step/pkgmgr/step_recover_parser_plugins.cc
new file mode 100644 (file)
index 0000000..5cbd53f
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright (c) 2018 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/pkgmgr/step_recover_parser_plugins.h"
+
+#include <pkgmgr-info.h>
+
+#include <boost/filesystem/path.hpp>
+
+#include "common/plugins/plugin.h"
+#include "common/step/pkgmgr/step_run_parser_plugins.h"
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace {
+
+ci::Plugin::ActionType GetActionType(ci::InstallerContext* context) {
+  ci::RequestType type = context->recovery_info.get().recovery_file->type();
+  switch (type) {
+    case ci::RequestType::Install:
+    case ci::RequestType::MountInstall:
+      return ci::Plugin::ActionType::RecoverInstall;
+    case ci::RequestType::Update:
+    case ci::RequestType::Delta:
+    case ci::RequestType::MountUpdate:
+    case ci::RequestType::ReadonlyUpdateInstall:
+      return ci::Plugin::ActionType::RecoverUpgrade;
+    default:
+      LOG(ERROR) << "Invalid request type : " << static_cast<int>(type);
+      return ci::Plugin::ActionType::Unknown;
+  }
+}
+
+}  // namespace
+
+namespace common_installer {
+namespace pkgmgr {
+
+Step::Status StepRecoverParserPlugin::RecoveryNew() {
+  return RecoverPlugin();
+}
+
+Step::Status StepRecoverParserPlugin::RecoveryUpdate() {
+  return RecoverPlugin();
+}
+
+Step::Status StepRecoverParserPlugin::RecoverPlugin() {
+  if (!SetXmlPath()) {
+    LOG(ERROR) << "Failed to set xml path for plugin, but continue";
+    return Status::OK;
+  }
+  StepRunParserPlugin plugin(context_, GetActionType(context_));
+  if (plugin.process() != Step::Status::OK) {
+    LOG(ERROR) << "Failed to execute plugin properly, but conitnue";
+    return Status::OK;
+  }
+  return Status::OK;
+}
+
+bool StepRecoverParserPlugin::SetXmlPath() {
+  if (context_->pkgid.get().empty())
+    return false;
+  bf::path xml_path =
+      bf::path(getUserManifestPath(context_->uid.get(),
+          context_->is_readonly_package.get()))
+      / context_->pkgid.get();
+  xml_path += ".xml";
+  context_->xml_path.set(xml_path);
+  return true;
+}
+
+}  // namespace pkgmgr
+}  // namespace common_installer
diff --git a/src/common/step/pkgmgr/step_recover_parser_plugins.h b/src/common/step/pkgmgr/step_recover_parser_plugins.h
new file mode 100644 (file)
index 0000000..140d082
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (c) 2018 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_PKGMGR_STEP_RECOVER_PARSER_PLUGINS_H_
+#define COMMON_STEP_PKGMGR_STEP_RECOVER_PARSER_PLUGINS_H_
+
+#include <manifest_parser/utils/logging.h>
+
+#include "common/installer_context.h"
+#include "common/step/recovery/step_recovery.h"
+
+namespace common_installer {
+namespace pkgmgr {
+
+class StepRecoverParserPlugin : public recovery::StepRecovery {
+ public:
+  using StepRecovery::StepRecovery;
+
+  Status RecoveryNew() override;
+  Status RecoveryUpdate() override;
+
+ private:
+  Status RecoverPlugin();
+  bool SetXmlPath();
+
+  STEP_NAME(RecoverParserPlugin)
+};
+
+}  // namespace pkgmgr
+}  // namespace common_installer
+
+#endif  // COMMON_STEP_PKGMGR_STEP_RECOVER_PARSER_PLUGINS_H_
index 45c4e4a..70fb69a 100644 (file)
@@ -24,7 +24,7 @@ namespace common_installer {
 namespace pkgmgr {
 
 
-common_installer::Step::Status StepRemoveManifest::process() {
+common_installer::Step::Status StepRemoveManifest::clean() {
   bf::path manifest_path;
   if (context_->request_type.get() == RequestType::ReadonlyUpdateUninstall) {
     manifest_path = bf::path(tzplatform_getenv(TZ_SYS_RW_PACKAGES)) /
index 6f19533..a2b9e03 100644 (file)
@@ -25,9 +25,8 @@ class StepRemoveManifest : public Step {
    *
    * \return Status::OK if success, Status::ERROR otherwise
    */
-  Status process() override;
-
-  Status clean() override { return Status::OK; }
+  Status process() override { return Status::OK; }
+  Status clean() override;
   Status undo() override { return Status::OK; }
   Status precheck() override { return Status::OK; }
 
index 4dedb0c..d0ff8dc 100644 (file)
@@ -43,16 +43,21 @@ Step::Status StepRunParserPlugin::process() {
 Step::Status StepRunParserPlugin::undo() {
   // For update, we need to reread configuration of old version of widget
   // so running whole process from beginning
-  if (action_type_ == Plugin::ActionType::Install) {
+  if (action_type_ == Plugin::ActionType::Install)
     ProcessPlugins(context_->xml_path.get(), context_->manifest_data.get(),
-                   Plugin::ActionType::Uninstall);
-  } else if (action_type_ == Plugin::ActionType::Upgrade) {
+                   Plugin::ActionType::Undo);
+  else if (action_type_ == Plugin::ActionType::Upgrade)
     ProcessPlugins(context_->backup_xml_path.get(),
                    context_->old_manifest_data.get(),
-                   Plugin::ActionType::Upgrade);
-  }
+                   Plugin::ActionType::Undo);
   return Status::OK;
 }
 
+Step::Status StepRunParserPlugin::clean() {
+  return ProcessPlugins(context_->xml_path.get(),
+                        context_->manifest_data.get(),
+                        Plugin::ActionType::Clean);
+}
+
 }  // namespace pkgmgr
 }  // namespace common_installer
index 4b9c41a..5fd1864 100644 (file)
@@ -24,7 +24,7 @@ class StepRunParserPlugin : public Step {
                                Plugin::ActionType action_type);
 
   Step::Status process() override;
-  Step::Status clean() { return Status::OK; }
+  Step::Status clean() override;
   Step::Status undo() override;
   Step::Status precheck() { return Status::OK; }
 
index c92ab08..4a79252 100644 (file)
@@ -81,12 +81,6 @@ Step::Status StepUnregisterApplication::process() {
     LOG(ERROR) << "Failed to unregister package into database";
   }
 
-  if (!context_->partial_rw.get()) {
-    // remove manifest file
-    if (!Remove(context_->xml_path.get()))
-      return Status::MANIFEST_ERROR;
-  }
-
   LOG(DEBUG) << "Successfully unregister the application";
 
   return Status::OK;