diff options
author | Richard Hughes <richard@hughsie.com> | 2016-08-01 09:10:56 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-08-01 09:49:13 +0100 |
commit | 0b60c91524b700d5dcdcccde23af7fc117cbcb9b (patch) | |
tree | 6d2f7dc6823c85619e3139d60be9b73454ffb5de | |
parent | a72b1063ff6c5d9003959181fca7da8d6628500b (diff) | |
download | appstream-glib-0b60c91524b700d5dcdcccde23af7fc117cbcb9b.tar.gz |
Restrict addons to the same scope and bundle kind
-rw-r--r-- | libappstream-glib/as-app-private.h | 1 | ||||
-rw-r--r-- | libappstream-glib/as-app.c | 10 | ||||
-rw-r--r-- | libappstream-glib/as-store.c | 52 |
3 files changed, 38 insertions, 25 deletions
diff --git a/libappstream-glib/as-app-private.h b/libappstream-glib/as-app-private.h index dd6f357..6230a50 100644 --- a/libappstream-glib/as-app-private.h +++ b/libappstream-glib/as-app-private.h @@ -87,6 +87,7 @@ guint as_app_get_name_size (AsApp *app); guint as_app_get_comment_size (AsApp *app); guint as_app_get_description_size (AsApp *app); GPtrArray *as_app_get_search_tokens (AsApp *app); +AsBundleKind as_app_get_bundle_kind (AsApp *app); GNode *as_app_node_insert (AsApp *app, GNode *parent, diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 0b1b5d4..215c230 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -515,8 +515,8 @@ as_app_equal_array_str (GPtrArray *v1, GPtrArray *v2) g_ptr_array_index (v2, 0)) == 0; } -static AsBundleKind -as_app_get_unique_id_bundle (AsApp *app) +AsBundleKind +as_app_get_bundle_kind (AsApp *app) { AsAppPrivate *priv = GET_PRIVATE (app); @@ -575,8 +575,8 @@ as_app_equal (AsApp *app1, AsApp *app2) if (!as_app_equal_array_str (priv1->architectures, priv2->architectures)) return FALSE; - if (!as_app_equal_int (as_app_get_unique_id_bundle (app1), - as_app_get_unique_id_bundle (app2))) + if (!as_app_equal_int (as_app_get_bundle_kind (app1), + as_app_get_bundle_kind (app2))) return FALSE; return TRUE; } @@ -614,7 +614,7 @@ as_app_get_unique_id (AsApp *app) kind_str = as_app_kind_to_string (priv->kind); if (priv->scope != AS_APP_SCOPE_UNKNOWN) scope_str = as_app_scope_to_string (priv->scope); - bundle_kind = as_app_get_unique_id_bundle (app); + bundle_kind = as_app_get_bundle_kind (app); if (bundle_kind != AS_BUNDLE_KIND_UNKNOWN) bundle_str = as_bundle_kind_to_string (bundle_kind); id_str = as_app_get_id_no_prefix (app); diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index a3b533c..6c8fdb2 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -1002,37 +1002,49 @@ as_store_add_app (AsStore *store, AsApp *app) } static void -as_store_match_addons (AsStore *store) +as_store_match_addons_app (AsStore *store, AsApp *app) { - AsApp *app; - AsApp *parent; - AsStorePrivate *priv = GET_PRIVATE (store); GPtrArray *plugin_ids; - const gchar *tmp; guint i; guint j; + + plugin_ids = as_app_get_extends (app); + if (plugin_ids->len == 0) { + g_warning ("%s was of type addon but had no extends", + as_app_get_id (app)); + return; + } + for (j = 0; j < plugin_ids->len; j++) { + g_autoptr(GPtrArray) parents = NULL; + const gchar *tmp = g_ptr_array_index (plugin_ids, j); + + /* restrict to same scope and bundle kind */ + parents = as_store_get_apps_by_id (store, tmp); + for (i = 0; i < parents->len; i++) { + AsApp *parent = g_ptr_array_index (parents, i); + if (as_app_get_scope (app) != as_app_get_scope (parent)) + continue; + if (as_app_get_bundle_kind (app) != as_app_get_bundle_kind (parent)) + continue; + as_app_add_addon (parent, app); + } + } +} + +static void +as_store_match_addons (AsStore *store) +{ + AsStorePrivate *priv = GET_PRIVATE (store); + guint i; g_autoptr(AsProfileTask) ptask = NULL; /* profile */ ptask = as_profile_start_literal (priv->profile, "AsStore:match-addons"); - for (i = 0; i < priv->array->len; i++) { - app = g_ptr_array_index (priv->array, i); + AsApp *app = g_ptr_array_index (priv->array, i); if (as_app_get_kind (app) != AS_APP_KIND_ADDON) continue; - plugin_ids = as_app_get_extends (app); - if (plugin_ids->len == 0) { - g_warning ("%s was of type addon but had no extends", - as_app_get_id (app)); - continue; - } - for (j = 0; j < plugin_ids->len; j++) { - tmp = g_ptr_array_index (plugin_ids, j); - parent = g_hash_table_lookup (priv->hash_id, tmp); - if (parent == NULL) - continue; - as_app_add_addon (parent, app); - } + as_store_match_addons_app (store, app); } } |