Fix that plugin is executed several times 48/304848/2
authorIlho Kim <ilho159.kim@samsung.com>
Wed, 24 Jan 2024 07:22:42 +0000 (16:22 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Wed, 24 Jan 2024 09:03:41 +0000 (18:03 +0900)
There are cases in which the plugin is executed even if it is not
actually a removed plugin when performing a removed plugin
because the plugin info can have duplicate data

Change-Id: Ib2e793e01ee281e9a2496c56b080af2114eeece6
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/plugins/category_plugin.cc
src/common/plugins/metadata_plugin.cc
src/common/plugins/metadata_plugin.h

index 78a901d..01b8277 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <algorithm>
 #include <map>
-#include <vector>
+#include <set>
 
 #include "common/utils/glist_range.h"
 
@@ -81,23 +81,21 @@ bool CategoryPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
   if (tag.empty())
     return false;
 
-  std::vector<std::string> appid_list;
+  std::set<std::string> appid_list;
   if (action_type == ActionType::Upgrade) {
     if (pkgmgrinfo_plugininfo_foreach_plugininfo(manifest->package,
         CategoryPlugin::kType,
         plugin_info_.name().c_str(),
         [](const char*, const char* appid, const char*,
             const char*, void* user_data) -> int {
-          auto* list =
-              static_cast<std::vector<std::string>*>(user_data);
-          list->emplace_back(std::string(appid));
+          auto* list = static_cast<std::set<std::string>*>(user_data);
+          list->emplace(std::string(appid));
           return PMINFO_R_OK;
         },
         &appid_list) != PMINFO_R_OK) {
       LOG(ERROR) << "Failed to get previous execution info";
       return false;
     }
-    std::sort(appid_list.begin(), appid_list.end());
   }
 
   for (application_x* app : GListRange<application_x*>(manifest->application)) {
@@ -131,11 +129,10 @@ bool CategoryPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
     if (!category_list) {
       if (action_type != ActionType::Upgrade)
         continue;
-      auto iter = std::lower_bound(appid_list.begin(), appid_list.end(),
-                                     app->appid);
-      if (iter != appid_list.end() && *iter == app->appid) {
+      auto iter = appid_list.find(app->appid);
+      if (iter != appid_list.end()) {
         name = GetFunctionName(ActionType::Removed);
-        iter = appid_list.erase(iter);
+        appid_list.erase(iter);
         category_list = nullptr;
       } else {
         continue;
@@ -146,10 +143,7 @@ bool CategoryPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
         g_list_free_full(category_list, &ClearCategoryDetail);
         return false;
       }
-      auto iter = std::lower_bound(appid_list.begin(), appid_list.end(),
-                                     app->appid);
-      if (iter != appid_list.end() && *iter == app->appid)
-        appid_list.erase(iter);
+      appid_list.erase(app->appid);
     }
     int result = 0;
     Exec(name, &result, manifest->package, app->appid, category_list);
index 0cf2a53..3cd4148 100644 (file)
@@ -9,7 +9,7 @@
 
 #include <algorithm>
 #include <map>
-#include <vector>
+#include <set>
 
 #include "common/utils/glist_range.h"
 
@@ -94,22 +94,21 @@ bool MetadataPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
   if (tag.empty())
     return false;
 
+  std::set<std::string> appid_list;
   if (action_type == ActionType::Upgrade) {
     if (pkgmgrinfo_plugininfo_foreach_plugininfo(manifest->package,
         MetadataPlugin::kType,
         plugin_info_.name().c_str(),
         [](const char*, const char* appid, const char*,
             const char*, void* user_data) -> int {
-          auto* appid_list =
-              static_cast<std::vector<std::string>*>(user_data);
-          appid_list->emplace_back(std::string(appid));
+          auto* list = static_cast<std::set<std::string>*>(user_data);
+          list->emplace(std::string(appid));
           return PMINFO_R_OK;
         },
-        &appid_list_) != PMINFO_R_OK) {
+        &appid_list) != PMINFO_R_OK) {
       LOG(ERROR) << "Failed to get previous execution info";
       return false;
     }
-    std::sort(appid_list_.begin(), appid_list_.end());
   }
 
   for (application_x* app : GListRange<application_x*>(manifest->application)) {
@@ -156,10 +155,7 @@ bool MetadataPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
         g_list_free_full(md_list, &ClearMetadataDetail);
         return false;
       }
-      auto iter = std::lower_bound(appid_list_.begin(), appid_list_.end(),
-                                     app->appid);
-      if (iter != appid_list_.end() && *iter == app->appid)
-        appid_list_.erase(iter);
+      appid_list.erase(app->appid);
     }
     int result = 0;
     Exec(name, &result, manifest->package, app->appid, md_list);
@@ -177,7 +173,7 @@ bool MetadataPlugin::Run(xmlDocPtr /*doc_ptr*/, manifest_x* manifest,
     name = GetFunctionName(action_type);
   else
     name = GetFunctionName(ActionType::Removed);
-  for (const auto& appid : appid_list_) {
+  for (const auto& appid : appid_list) {
     int result = 0;
     Exec(name, &result, manifest->package, appid.c_str(), nullptr);
     if (result) {
index 492a3e4..2e004ad 100644 (file)
@@ -7,7 +7,6 @@
 
 #include <memory>
 #include <string>
-#include <vector>
 
 #include "common/plugins/plugin.h"
 
@@ -27,7 +26,6 @@ class MetadataPlugin : public Plugin {
 
   using Plugin::Plugin;
 
-  std::vector<std::string> appid_list_;
   SCOPE_LOG_TAG(MetadataPlugin)
 };