From 473c520e38845f86f5f623e8a4f261bf55d7ec72 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 11 Jan 2018 21:06:16 +0000 Subject: [PATCH] Add in extra metadata to the uploaded reports Save the dependency versions, architecture and the kernel versions in the history database as metadata as it may be different to the time of upload. --- src/fu-engine.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/fu-engine.c b/src/fu-engine.c index e04a9b914..b532ce791 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "fwupd-common-private.h" #include "fwupd-enums-private.h" @@ -1199,6 +1200,43 @@ fu_engine_get_item_by_wildcard (FuEngine *self, AsStore *store, GError **error) return NULL; } +static GHashTable * +fu_engine_get_report_metadata (FuEngine *self) +{ + GHashTable *hash; + struct utsname name_tmp = { 0 }; + + /* used by pretty much every plugin and are hard deps of fwupd */ + hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + g_hash_table_insert (hash, + g_strdup ("FwupdVersion"), + g_strdup (VERSION)); + g_hash_table_insert (hash, + g_strdup ("AppstreamGlibVersion"), + g_strdup_printf ("%i.%i.%i", + AS_MAJOR_VERSION, + AS_MINOR_VERSION, + AS_MICRO_VERSION)); + g_hash_table_insert (hash, + g_strdup ("GUsbVersion"), + g_strdup_printf ("%i.%i.%i", + G_USB_MAJOR_VERSION, + G_USB_MINOR_VERSION, + G_USB_MICRO_VERSION)); + + /* kernel version is often important for debugging failures */ + if (uname (&name_tmp) >= 0) { + g_hash_table_insert (hash, + g_strdup ("CpuArchitecture"), + g_strdup (name_tmp.machine)); + g_hash_table_insert (hash, + g_strdup ("KernelVersion"), + g_strdup (name_tmp.release)); + } + + return hash; +} + /** * fu_engine_install: * @self: A #FuEngine @@ -1236,6 +1274,7 @@ fu_engine_install (FuEngine *self, g_autoptr(FwupdRelease) release_history = fwupd_release_new (); g_autoptr(GBytes) blob_fw2 = NULL; g_autoptr(GError) error_local = NULL; + g_autoptr(GHashTable) metadata_hash = NULL; g_return_val_if_fail (FU_IS_ENGINE (self), FALSE); g_return_val_if_fail (device_id != NULL, FALSE); @@ -1447,6 +1486,10 @@ fu_engine_install (FuEngine *self, /* mark this as modified even if we actually fail to do the update */ fu_device_set_modified (device, (guint64) g_get_real_time () / G_USEC_PER_SEC); + /* build the version metadata */ + metadata_hash = fu_engine_get_report_metadata (self); + fwupd_release_add_metadata (release_history, metadata_hash); + /* add device to database */ checksum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, blob_cab); fwupd_release_set_version (release_history, version);