diff options
author | Richard Hughes <richard@hughsie.com> | 2015-01-22 21:27:52 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-01-22 21:59:01 +0000 |
commit | 8b0ec4d422e84876923c3473ea680587c8a7ebec (patch) | |
tree | 8e40d89a71aaa10e9cef0a9215fcaf49eda25319 /libappstream-builder | |
parent | 775f59405fd9f5269ff7d4e3d0a78133f7af5de2 (diff) | |
download | appstream-glib-8b0ec4d422e84876923c3473ea680587c8a7ebec.tar.gz |
trivial: Add asb_plugin_match_glob()
This allows us to modify the prefix in the future for bundles.
Diffstat (limited to 'libappstream-builder')
-rw-r--r-- | libappstream-builder/asb-plugin.c | 16 | ||||
-rw-r--r-- | libappstream-builder/asb-plugin.h | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-dbus.c | 4 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-desktop.c | 4 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-font.c | 4 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-gir.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-gresource.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-gstreamer.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-hardcoded.c | 11 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-ibus-sql.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-ibus-xml.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-kde-notifyrc.c | 8 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-kde-services.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-metainfo.c | 2 | ||||
-rw-r--r-- | libappstream-builder/plugins/asb-plugin-nm.c | 2 |
15 files changed, 41 insertions, 24 deletions
diff --git a/libappstream-builder/asb-plugin.c b/libappstream-builder/asb-plugin.c index 26903d0..293653b 100644 --- a/libappstream-builder/asb-plugin.c +++ b/libappstream-builder/asb-plugin.c @@ -30,6 +30,7 @@ #include "config.h" #include <glib.h> +#include <fnmatch.h> #include "asb-plugin.h" #include "asb-utils.h" @@ -118,3 +119,18 @@ asb_plugin_add_glob (GPtrArray *array, const gchar *glob) { g_ptr_array_add (array, asb_glob_value_new (glob, "")); } + +/** + * asb_plugin_match_glob: + * @glob: a filename glob + * @value: a filename value + * + * Matches a value against a glob. + * + * Since: 0.3.5 + **/ +gboolean +asb_plugin_match_glob (const gchar *glob, const gchar *value) +{ + return (fnmatch (glob, value, 0) == 0); +} diff --git a/libappstream-builder/asb-plugin.h b/libappstream-builder/asb-plugin.h index f1b7c8e..56b0695 100644 --- a/libappstream-builder/asb-plugin.h +++ b/libappstream-builder/asb-plugin.h @@ -101,6 +101,8 @@ void asb_plugin_add_app (GList **list, AsApp *app); void asb_plugin_add_glob (GPtrArray *array, const gchar *glob); +gboolean asb_plugin_match_glob (const gchar *glob, + const gchar *value); G_END_DECLS diff --git a/libappstream-builder/plugins/asb-plugin-dbus.c b/libappstream-builder/plugins/asb-plugin-dbus.c index a0ed174..5d49cee 100644 --- a/libappstream-builder/plugins/asb-plugin-dbus.c +++ b/libappstream-builder/plugins/asb-plugin-dbus.c @@ -49,7 +49,7 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) static gboolean _asb_plugin_check_filename_system (const gchar *filename) { - if (fnmatch ("/usr/share/dbus-1/system-services/*.service", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/dbus-1/system-services/*.service", filename)) return TRUE; return FALSE; } @@ -60,7 +60,7 @@ _asb_plugin_check_filename_system (const gchar *filename) static gboolean _asb_plugin_check_filename_session (const gchar *filename) { - if (fnmatch ("/usr/share/dbus-1/services/*.service", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/dbus-1/services/*.service", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-desktop.c b/libappstream-builder/plugins/asb-plugin-desktop.c index bde3ce0..ef82929 100644 --- a/libappstream-builder/plugins/asb-plugin-desktop.c +++ b/libappstream-builder/plugins/asb-plugin-desktop.c @@ -58,9 +58,9 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) static gboolean _asb_plugin_check_filename (const gchar *filename) { - if (fnmatch ("/usr/share/applications/*.desktop", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/applications/*.desktop", filename)) return TRUE; - if (fnmatch ("/usr/share/applications/kde4/*.desktop", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/applications/kde4/*.desktop", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-font.c b/libappstream-builder/plugins/asb-plugin-font.c index d47695f..0407ff2 100644 --- a/libappstream-builder/plugins/asb-plugin-font.c +++ b/libappstream-builder/plugins/asb-plugin-font.c @@ -63,9 +63,9 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) static gboolean _asb_plugin_check_filename (const gchar *filename) { - if (fnmatch ("/usr/share/fonts/*/*.otf", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/fonts/*/*.otf", filename)) return TRUE; - if (fnmatch ("/usr/share/fonts/*/*.ttf", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/fonts/*/*.ttf", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-gir.c b/libappstream-builder/plugins/asb-plugin-gir.c index 6217b9e..8244bdb 100644 --- a/libappstream-builder/plugins/asb-plugin-gir.c +++ b/libappstream-builder/plugins/asb-plugin-gir.c @@ -48,7 +48,7 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) static gboolean _asb_plugin_check_filename (const gchar *filename) { - if (fnmatch ("/usr/share/*/*.gir", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/*/*.gir", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-gresource.c b/libappstream-builder/plugins/asb-plugin-gresource.c index b9c291a..7703b16 100644 --- a/libappstream-builder/plugins/asb-plugin-gresource.c +++ b/libappstream-builder/plugins/asb-plugin-gresource.c @@ -87,7 +87,7 @@ asb_plugin_process_app (AsbPlugin *plugin, GError *error_local = NULL; _cleanup_free_ gchar *filename = NULL; - if (!g_str_has_prefix (filelist[i], "/usr/bin/")) + if (!asb_plugin_match_glob ("/usr/bin/*", filelist[i])) continue; if (as_app_has_kudo_kind (AS_APP (app), AS_KUDO_KIND_APP_MENU)) break; diff --git a/libappstream-builder/plugins/asb-plugin-gstreamer.c b/libappstream-builder/plugins/asb-plugin-gstreamer.c index d3c936c..c5fa518 100644 --- a/libappstream-builder/plugins/asb-plugin-gstreamer.c +++ b/libappstream-builder/plugins/asb-plugin-gstreamer.c @@ -48,7 +48,7 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) gboolean asb_plugin_check_filename (AsbPlugin *plugin, const gchar *filename) { - if (fnmatch ("/usr/lib64/gstreamer-1.0/libgst*.so", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/lib64/gstreamer-1.0/libgst*.so", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-hardcoded.c b/libappstream-builder/plugins/asb-plugin-hardcoded.c index 4b99ae9..17e8f7d 100644 --- a/libappstream-builder/plugins/asb-plugin-hardcoded.c +++ b/libappstream-builder/plugins/asb-plugin-hardcoded.c @@ -203,8 +203,7 @@ asb_plugin_process_app (AsbPlugin *plugin, /* look for any installed docs */ filelist = asb_package_get_filelist (pkg); for (i = 0; filelist[i] != NULL; i++) { - if (g_str_has_prefix (filelist[i], - "/usr/share/help/")) { + if (asb_plugin_match_glob ("/usr/share/help/*", filelist[i])) { as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_USER_DOCS); break; @@ -213,8 +212,8 @@ asb_plugin_process_app (AsbPlugin *plugin, /* look for a shell search provider */ for (i = 0; filelist[i] != NULL; i++) { - if (g_str_has_prefix (filelist[i], - "/usr/share/gnome-shell/search-providers/")) { + if (asb_plugin_match_glob ("/usr/share/gnome-shell/search-providers/*", + filelist[i])) { as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_SEARCH_PROVIDER); break; @@ -223,8 +222,8 @@ asb_plugin_process_app (AsbPlugin *plugin, /* look for a high contrast icon */ for (i = 0; filelist[i] != NULL; i++) { - if (g_str_has_prefix (filelist[i], - "/usr/share/icons/HighContrast/")) { + if (asb_plugin_match_glob ("/usr/share/icons/HighContrast/*", + filelist[i])) { as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_HIGH_CONTRAST); break; diff --git a/libappstream-builder/plugins/asb-plugin-ibus-sql.c b/libappstream-builder/plugins/asb-plugin-ibus-sql.c index cffbc9b..0ba77dc 100644 --- a/libappstream-builder/plugins/asb-plugin-ibus-sql.c +++ b/libappstream-builder/plugins/asb-plugin-ibus-sql.c @@ -49,7 +49,7 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) static gboolean _asb_plugin_check_filename (const gchar *filename) { - if (fnmatch ("/usr/share/ibus-table/tables/*.db", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/ibus-table/tables/*.db", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-ibus-xml.c b/libappstream-builder/plugins/asb-plugin-ibus-xml.c index 2d47807..0f3ac67 100644 --- a/libappstream-builder/plugins/asb-plugin-ibus-xml.c +++ b/libappstream-builder/plugins/asb-plugin-ibus-xml.c @@ -50,7 +50,7 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) static gboolean _asb_plugin_check_filename (const gchar *filename) { - if (fnmatch ("/usr/share/ibus/component/*.xml", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/ibus/component/*.xml", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-kde-notifyrc.c b/libappstream-builder/plugins/asb-plugin-kde-notifyrc.c index df5668c..c485efd 100644 --- a/libappstream-builder/plugins/asb-plugin-kde-notifyrc.c +++ b/libappstream-builder/plugins/asb-plugin-kde-notifyrc.c @@ -58,10 +58,10 @@ asb_plugin_process_app (AsbPlugin *plugin, /* look for a shell search provider */ filelist = asb_package_get_filelist (pkg); for (i = 0; filelist[i] != NULL; i++) { - if (fnmatch ("/usr/share/kde4/apps/*/*.notifyrc", filelist[i], 0) == 0) { - as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_NOTIFICATIONS); - break; - } + if (!asb_plugin_match_glob ("/usr/share/kde4/apps/*/*.notifyrc", filelist[i])) + continue; + as_app_add_kudo_kind (AS_APP (app), AS_KUDO_KIND_NOTIFICATIONS); + break; } return TRUE; diff --git a/libappstream-builder/plugins/asb-plugin-kde-services.c b/libappstream-builder/plugins/asb-plugin-kde-services.c index b0257e9..1db073a 100644 --- a/libappstream-builder/plugins/asb-plugin-kde-services.c +++ b/libappstream-builder/plugins/asb-plugin-kde-services.c @@ -84,7 +84,7 @@ asb_plugin_process_app (AsbPlugin *plugin, for (i = 0; filelist[i] != NULL; i++) { _cleanup_error_free_ GError *error_local = NULL; _cleanup_free_ gchar *filename = NULL; - if (fnmatch ("/usr/share/kde4/services/*.desktop", filelist[i], 0) != 0) + if (!asb_plugin_match_glob ("/usr/share/kde4/services/*.desktop", filelist[i])) continue; filename = g_build_filename (tmpdir, filelist[i], NULL); if (!asb_plugin_process_filename (filename, diff --git a/libappstream-builder/plugins/asb-plugin-metainfo.c b/libappstream-builder/plugins/asb-plugin-metainfo.c index 490d5ae..0cb7b82 100644 --- a/libappstream-builder/plugins/asb-plugin-metainfo.c +++ b/libappstream-builder/plugins/asb-plugin-metainfo.c @@ -48,7 +48,7 @@ asb_plugin_add_globs (AsbPlugin *plugin, GPtrArray *globs) static gboolean _asb_plugin_check_filename (const gchar *filename) { - if (fnmatch ("/usr/share/appdata/*.metainfo.xml", filename, 0) == 0) + if (asb_plugin_match_glob ("/usr/share/appdata/*.metainfo.xml", filename)) return TRUE; return FALSE; } diff --git a/libappstream-builder/plugins/asb-plugin-nm.c b/libappstream-builder/plugins/asb-plugin-nm.c index 25a90ec..569e9df 100644 --- a/libappstream-builder/plugins/asb-plugin-nm.c +++ b/libappstream-builder/plugins/asb-plugin-nm.c @@ -93,7 +93,7 @@ asb_plugin_process_app (AsbPlugin *plugin, GError *error_local = NULL; _cleanup_free_ gchar *filename = NULL; - if (!g_str_has_prefix (filelist[i], "/usr/bin/")) + if (!asb_plugin_match_glob ("/usr/bin/*", filelist[i])) continue; if (as_app_has_kudo_kind (AS_APP (app), AS_KUDO_KIND_APP_MENU)) break; |