diff options
author | Ilho Kim <ilho159.kim@samsung.com> | 2024-01-24 16:22:42 +0900 |
---|---|---|
committer | Ilho Kim <ilho159.kim@samsung.com> | 2024-01-24 18:03:41 +0900 |
commit | f1806004819258042be0508977a09e0b91e73ba7 (patch) | |
tree | 3ff8444cc33cea101d5792f736405d07c9a3d657 | |
parent | 992e6bf05f455204d8b3c45c9c091b08311e126f (diff) | |
download | app-installers-f1806004819258042be0508977a09e0b91e73ba7.tar.gz app-installers-f1806004819258042be0508977a09e0b91e73ba7.tar.bz2 app-installers-f1806004819258042be0508977a09e0b91e73ba7.zip |
Fix that plugin is executed several times
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>
-rw-r--r-- | src/common/plugins/category_plugin.cc | 22 | ||||
-rw-r--r-- | src/common/plugins/metadata_plugin.cc | 18 | ||||
-rw-r--r-- | src/common/plugins/metadata_plugin.h | 2 |
3 files changed, 15 insertions, 27 deletions
diff --git a/src/common/plugins/category_plugin.cc b/src/common/plugins/category_plugin.cc index 78a901db..01b82771 100644 --- a/src/common/plugins/category_plugin.cc +++ b/src/common/plugins/category_plugin.cc @@ -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); diff --git a/src/common/plugins/metadata_plugin.cc b/src/common/plugins/metadata_plugin.cc index 0cf2a53f..3cd41487 100644 --- a/src/common/plugins/metadata_plugin.cc +++ b/src/common/plugins/metadata_plugin.cc @@ -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) { diff --git a/src/common/plugins/metadata_plugin.h b/src/common/plugins/metadata_plugin.h index 492a3e49..2e004ade 100644 --- a/src/common/plugins/metadata_plugin.h +++ b/src/common/plugins/metadata_plugin.h @@ -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) }; |