summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2018-02-23 15:24:41 +0000
committerRichard Hughes <richard@hughsie.com>2018-02-23 16:12:43 +0000
commit6183cf7cdf014f1149c516a054f1f877804604ad (patch)
tree8de37127fb45eb1e579137751567930fd75bc83c
parent1f7ff84a04c227bccb60c76f461f3dccbe372f7a (diff)
downloadappstream-glib-6183cf7cdf014f1149c516a054f1f877804604ad.tar.gz
trivial: Never add duplicated <requires> nodes for components
-rw-r--r--libappstream-glib/as-app.c9
-rw-r--r--libappstream-glib/as-require.c35
-rw-r--r--libappstream-glib/as-require.h2
3 files changed, 46 insertions, 0 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 474af29..a9efe09 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -3582,6 +3582,15 @@ void
as_app_add_require (AsApp *app, AsRequire *require)
{
AsAppPrivate *priv = GET_PRIVATE (app);
+
+ /* handle untrusted */
+ if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_DUPLICATES) > 0) {
+ for (guint i = 0; i < priv->requires->len; i++) {
+ AsRequire *req_tmp = g_ptr_array_index (priv->requires, i);
+ if (as_require_equal (require, req_tmp))
+ return;
+ }
+ }
g_ptr_array_add (priv->requires, g_object_ref (require));
}
diff --git a/libappstream-glib/as-require.c b/libappstream-glib/as-require.c
index 66ef88d..da14b5d 100644
--- a/libappstream-glib/as-require.c
+++ b/libappstream-glib/as-require.c
@@ -405,6 +405,41 @@ as_require_version_compare (AsRequire *require,
}
/**
+ * as_require_equal:
+ * @require1: a #AsRequire instance.
+ * @require2: a #AsRequire instance.
+ *
+ * Checks if two requires are the same.
+ *
+ * Returns: %TRUE for success
+ *
+ * Since: 0.7.7
+ **/
+gboolean
+as_require_equal (AsRequire *require1, AsRequire *require2)
+{
+ AsRequirePrivate *priv1 = GET_PRIVATE (require1);
+ AsRequirePrivate *priv2 = GET_PRIVATE (require2);
+
+ /* trivial */
+ if (require1 == require2)
+ return TRUE;
+
+ /* check for equality */
+ if (priv1->kind != priv2->kind)
+ return FALSE;
+ if (priv1->compare != priv2->compare)
+ return FALSE;
+ if (g_strcmp0 (priv1->version, priv2->version) != 0)
+ return FALSE;
+ if (g_strcmp0 (priv1->value, priv2->value) != 0)
+ return FALSE;
+
+ /* success */
+ return TRUE;
+}
+
+/**
* as_require_node_insert: (skip)
* @require: a #AsRequire instance.
* @parent: the parent #GNode to use..
diff --git a/libappstream-glib/as-require.h b/libappstream-glib/as-require.h
index d3a6b5f..ca2797f 100644
--- a/libappstream-glib/as-require.h
+++ b/libappstream-glib/as-require.h
@@ -121,6 +121,8 @@ void as_require_set_value (AsRequire *require,
gboolean as_require_version_compare (AsRequire *require,
const gchar *version,
GError **error);
+gboolean as_require_equal (AsRequire *require1,
+ AsRequire *require2);
G_END_DECLS