[gnome-software/wip/hughsie/fwupd: 17/21] packagekit-refine: Only get package information for local files we support



commit cac4b0da32e4bfb7f686721cbe656e75f21caf8e
Author: Richard Hughes <richard hughsie com>
Date:   Mon Mar 9 11:08:21 2015 +0000

    packagekit-refine: Only get package information for local files we support

 src/plugins/gs-plugin-packagekit-refresh.c |   52 ++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index d2a6ecc..1a746e2 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -178,6 +178,48 @@ gs_plugin_packagekit_refresh_set_text (GsApp *app, const gchar *text)
 }
 
 /**
+ * gs_plugin_packagekit_refresh_content_type_matches:
+ */
+static gboolean
+gs_plugin_packagekit_refresh_content_type_matches (const gchar *filename,
+                                                  gboolean *matches,
+                                                  GCancellable *cancellable,
+                                                  GError **error)
+{
+       const gchar *tmp;
+       guint i;
+       _cleanup_object_unref_ GFile *file = NULL;
+       _cleanup_object_unref_ GFileInfo *info = NULL;
+       const gchar *mimetypes[] = {
+               "application/x-app-package",
+               "application/x-deb",
+               "application/x-redhat-package-manager",
+               "application/x-rpm",
+               NULL };
+
+       /* get content type */
+       file = g_file_new_for_path (filename);
+       info = g_file_query_info (file,
+                                 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+                                 G_FILE_QUERY_INFO_NONE,
+                                 cancellable,
+                                 error);
+       if (info == NULL)
+               return FALSE;
+       tmp = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+
+       /* match any */
+       *matches = FALSE;
+       for (i = 0; mimetypes[i] != NULL; i++) {
+               if (g_strcmp0 (tmp, mimetypes[i]) == 0) {
+                       *matches = TRUE;
+                       break;
+               }
+       }
+       return TRUE;
+}
+
+/**
  * gs_plugin_filename_to_app:
  */
 gboolean
@@ -188,6 +230,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
                           GError **error)
 {
        const gchar *package_id;
+       gboolean supported;
        PkDetails *item;
        PkResults *results = NULL;
        _cleanup_free_ gchar *basename = NULL;
@@ -196,6 +239,15 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
        _cleanup_ptrarray_unref_ GPtrArray *array = NULL;
        _cleanup_object_unref_ GsApp *app = NULL;
 
+       /* does this match any of the mimetypes we support */
+       if (!gs_plugin_packagekit_refresh_content_type_matches (filename,
+                                                               &supported,
+                                                               cancellable,
+                                                               error))
+               return FALSE;
+       if (!supported)
+               return TRUE;
+
        /* get details */
        files = g_strsplit (filename, "\t", -1);
        pk_client_set_cache_age (PK_CLIENT (plugin->priv->task), G_MAXUINT);


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