[gnome-software/wip/rancell/ubuntu-3-20-rebase: 21/52] Allow the provenance plugin to accept a glob



commit f81ae63ee725ee1cf53c7ce864b69ce6d7dd6357
Author: Richard Hughes <richard hughsie com>
Date:   Wed Apr 13 14:51:05 2016 +0100

    Allow the provenance plugin to accept a glob
    
    This makes it more suitable for use in Ubuntu.

 src/plugins/gs-plugin-provenance.c |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/src/plugins/gs-plugin-provenance.c b/src/plugins/gs-plugin-provenance.c
index 5f70a36..a86d839 100644
--- a/src/plugins/gs-plugin-provenance.c
+++ b/src/plugins/gs-plugin-provenance.c
@@ -21,6 +21,8 @@
 
 #include <config.h>
 
+#include <fnmatch.h>
+
 #include <gs-plugin.h>
 
 /*
@@ -95,17 +97,37 @@ gs_plugin_destroy (GsPlugin *plugin)
 }
 
 /**
+ * gs_utils_strv_fnmatch:
+ */
+static gboolean
+gs_utils_strv_fnmatch (gchar **strv, const gchar *str)
+{
+       guint i;
+
+       /* empty */
+       if (strv == NULL)
+               return FALSE;
+
+       /* look at each one */
+       for (i = 0; strv[i] != NULL; i++) {
+               if (fnmatch (strv[i], str, 0) == 0)
+                       return TRUE;
+       }
+       return FALSE;
+}
+
+/**
  * gs_plugin_provenance_refine_app:
  */
 static void
 gs_plugin_provenance_refine_app (GsPlugin *plugin, GsApp *app)
 {
        const gchar *origin;
-       const gchar * const *sources;
+       gchar **sources;
        guint i;
 
        /* nothing to search */
-       sources = (const gchar * const *) plugin->priv->sources;
+       sources = plugin->priv->sources;
        if (sources == NULL || sources[0] == NULL) {
                gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
                return;
@@ -113,7 +135,7 @@ gs_plugin_provenance_refine_app (GsPlugin *plugin, GsApp *app)
 
        /* simple case */
        origin = gs_app_get_origin (app);
-       if (origin != NULL && g_strv_contains (sources, origin)) {
+       if (origin != NULL && gs_utils_strv_fnmatch (sources, origin)) {
                gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
                return;
        }
@@ -128,7 +150,7 @@ gs_plugin_provenance_refine_app (GsPlugin *plugin, GsApp *app)
        if (g_str_has_prefix (origin + 1, "installed:"))
                origin += 10;
        for (i = 0; sources[i] != NULL; i++) {
-               if (g_strcmp0 (origin + 1, sources[i]) == 0) {
+               if (gs_utils_strv_fnmatch (sources, origin + 1)) {
                        gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
                        break;
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]