[gnome-software/wip/hughsie/GsPluginEvent: 19/24] fwupd: Add a cached source to improve error logging



commit 9931a3826f718a94b620dc142873f31d0d654c0a
Author: Richard Hughes <richard hughsie com>
Date:   Wed Sep 7 16:29:32 2016 +0100

    fwupd: Add a cached source to improve error logging

 src/plugins/gs-plugin-fwupd.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index a2f0f2f..16e5fcc 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -42,6 +42,7 @@ struct GsPluginData {
        GPtrArray               *to_download;
        GPtrArray               *to_ignore;
        GsApp                   *app_current;
+       GsApp                   *cached_origin;
        gchar                   *lvfs_sig_fn;
        gchar                   *lvfs_sig_hash;
        gchar                   *config_fn;
@@ -71,6 +72,8 @@ void
 gs_plugin_destroy (GsPlugin *plugin)
 {
        GsPluginData *priv = gs_plugin_get_data (plugin);
+       if (priv->cached_origin != NULL)
+               g_object_unref (priv->cached_origin);
        g_free (priv->lvfs_sig_fn);
        g_free (priv->lvfs_sig_hash);
        g_free (priv->config_fn);
@@ -179,6 +182,7 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        gsize len;
        g_autofree gchar *data = NULL;
        g_autoptr(GKeyFile) config = NULL;
+       g_autoptr(GsApp) app = NULL;
 
        /* read config file */
        config = g_key_file_new ();
@@ -192,6 +196,21 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
        if (priv->download_uri == NULL)
                return FALSE;
 
+       /* add source */
+       priv->cached_origin = gs_app_new (gs_plugin_get_name (plugin));
+       gs_app_set_kind (priv->cached_origin, AS_APP_KIND_GENERIC);
+       gs_app_set_state (priv->cached_origin, AS_APP_STATE_INSTALLED);
+       gs_app_set_scope (priv->cached_origin, AS_APP_SCOPE_SYSTEM);
+       gs_app_set_bundle_kind (priv->cached_origin, AS_BUNDLE_KIND_CABINET);
+       gs_app_set_origin_hostname (priv->cached_origin, priv->download_uri);
+       gs_app_set_origin_ui (priv->cached_origin, "Linux Vendor Firmware Project");
+
+       /* add the source to the plugin cache which allows us to match the
+        * unique ID to a GsApp when creating an event */
+       gs_plugin_cache_add (plugin,
+                            gs_app_get_unique_id (priv->cached_origin),
+                            priv->cached_origin);
+
        /* register D-Bus errors */
        fwupd_error_quark ();
        g_signal_connect (priv->client, "changed",
@@ -613,8 +632,10 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
                                        url_sig,
                                        cancellable,
                                        error);
-       if (data == NULL)
+       if (data == NULL) {
+               gs_plugin_error_add_unique_id (error, priv->cached_origin);
                return FALSE;
+       }
 
        /* is the signature hash the same as we had before? */
        checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1,
@@ -657,8 +678,10 @@ gs_plugin_fwupd_check_lvfs_metadata (GsPlugin *plugin,
                                      priv->download_uri,
                                      cache_fn_data,
                                      cancellable,
-                                     error))
+                                     error)) {
+               gs_plugin_error_add_unique_id (error, priv->cached_origin);
                return FALSE;
+       }
 
        /* phew, lets send all this to fwupd */
        if (!fwupd_client_update_metadata (priv->client,


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