Fix plugin manager 67/205167/8
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 30 Apr 2019 01:54:25 +0000 (10:54 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 14 May 2019 08:31:26 +0000 (08:31 +0000)
Fix crash when manifest is not provided.

Change-Id: I1f1c50856f3553c2a2f6d218a8af2ec2dbfd5b95
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/plugins/plugin_manager.cc
src/common/plugins/plugin_manager.h
src/common/plugins/plugin_xml_parser.cc
src/common/step/pkgmgr/step_run_parser_plugins.cc
src/unit_tests/plugins_unittest.cc

index 17045dc..f2ae706 100644 (file)
@@ -60,7 +60,8 @@ namespace common_installer {
 
 bool PluginManager::IsDataRemoved(const char* data_type,
                                   const std::string& data) {
-  return pkg_query_.IsPluginExecuted(std::string(data_type), data);
+  PkgQueryInterface pkg_query(pkgid_, uid_);
+  return pkg_query.IsPluginExecuted(data_type, data);
 }
 
 bool PluginManager::GenerateUnknownTagList(
index a1ef0f9..d1a946d 100644 (file)
@@ -27,13 +27,14 @@ class PluginManager {
 
   PluginManager(const boost::filesystem::path& xml_path,
                 const boost::filesystem::path& list_path,
+                const std::string& pkgid,
                 manifest_x* manifest,
                 uid_t uid)
       : xml_parser_(xml_path),
         list_parser_(list_path),
+        pkgid_(pkgid),
         manifest_(manifest),
-        uid_(uid),
-        pkg_query_(std::string(manifest_->package), uid_) {}
+        uid_(uid) {}
 
   bool LoadPlugins(Plugin::ActionType action_type);
   bool RunPlugins(Plugin::ActionType action_type);
@@ -46,9 +47,9 @@ class PluginManager {
 
   PluginsXmlParser xml_parser_;
   PluginsListParser list_parser_;
+  std::string pkgid_;
   manifest_x* manifest_;
   uid_t uid_;
-  PkgQueryInterface pkg_query_;
   std::vector<std::unique_ptr<Plugin>> loaded_plugins_;
 };
 
index f8882ed..717d0ac 100644 (file)
@@ -10,6 +10,7 @@ namespace common_installer {
 
 bool PluginsXmlParser::Parse() {
   if (path_.empty()) {
+    LOG(ERROR) << "Xml path is empty";
     return false;
   }
 
index 0a297e8..da80efa 100644 (file)
@@ -17,7 +17,8 @@ bool StepRunParserPlugin::InitPluginManager(
   // PLUGINS_LIST_INSTALL_PATH path generated from cmake
   const std::string listPath(PLUGINS_LIST_INSTALL_PATH);
   plugin_manager_.reset(
-    new PluginManager(xml_path.string(), listPath, manifest, uid));
+    new PluginManager(xml_path.string(), listPath, context_->pkgid.get(),
+      manifest, uid));
   if (!plugin_manager_.get()) {
     LOG(ERROR) << "plugin_manager_ reset fail, plugin_manager_ is NULL";
     return false;
index ca2a91b..c3a28ee 100644 (file)
@@ -175,7 +175,7 @@ TEST_F(PluginTest, PluginFactory_CreatingPlugins) {
           configuration::StepParseManifest::ManifestLocation::PACKAGE,         \
           configuration::StepParseManifest::StoreLocation::NORMAL);            \
       ASSERT_EQ(step.process(), Step::Status::OK);                             \
-      PluginManager manager(manifest, list,                                    \
+      PluginManager manager(manifest, list, context.pkgid.get(),               \
           context.manifest_data.get(), getuid());                              \
       ASSERT_TRUE(manager.LoadPlugins(ACTION));                                \
       manager.RunPlugins(ACTION);                                              \
@@ -205,7 +205,7 @@ CALLING_PLUGIN_FOR_ACTION_TEST(Uninstall, Plugin::ActionType::Uninstall)
             configuration::StepParseManifest::ManifestLocation::PACKAGE,       \
             configuration::StepParseManifest::StoreLocation::NORMAL);          \
         ASSERT_EQ(step.process(), Step::Status::OK);                           \
-        PluginManager manager(manifest, list,                                  \
+        PluginManager manager(manifest, list, context.pkgid.get(),             \
             context.manifest_data.get(), getuid());                            \
         ASSERT_TRUE(manager.LoadPlugins(ACTION));                              \
         ASSERT_FALSE(manager.RunPlugins(ACTION));                              \