mirror of
https://git.proxmox.com/git/fwupd
synced 2025-05-29 04:52:15 +00:00
Allow saving extra metadata in the history database
This will be used to store things like the kernel version in the future, and also means we can stop abusing the vendor property for the fwupd version.
This commit is contained in:
parent
d0adb23968
commit
38c59fcf4a
@ -88,10 +88,17 @@ fu_history_device_from_stmt (sqlite3_stmt *stmt)
|
|||||||
/* flags */
|
/* flags */
|
||||||
fu_device_set_flags (device, sqlite3_column_int64 (stmt, 7));
|
fu_device_set_flags (device, sqlite3_column_int64 (stmt, 7));
|
||||||
|
|
||||||
/* fwupd_version */
|
/* metadata */
|
||||||
tmp = (const gchar *) sqlite3_column_text (stmt, 8);
|
tmp = (const gchar *) sqlite3_column_text (stmt, 8);
|
||||||
if (tmp != NULL)
|
if (tmp != NULL) {
|
||||||
fwupd_release_set_vendor (release, tmp);
|
g_auto(GStrv) split = g_strsplit (tmp, ";", -1);
|
||||||
|
for (guint i = 0; split[i] != NULL; i++) {
|
||||||
|
g_auto(GStrv) kv = g_strsplit (split[i], "=", 2);
|
||||||
|
if (g_strv_length (kv) != 2)
|
||||||
|
continue;
|
||||||
|
fwupd_release_add_metadata_item (release, kv[0], kv[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* guid_default */
|
/* guid_default */
|
||||||
tmp = (const gchar *) sqlite3_column_text (stmt, 9);
|
tmp = (const gchar *) sqlite3_column_text (stmt, 9);
|
||||||
@ -195,7 +202,7 @@ fu_history_load (FuHistory *self, GError **error)
|
|||||||
"device_modified INTEGER DEFAULT 0,"
|
"device_modified INTEGER DEFAULT 0,"
|
||||||
"checksum TEXT DEFAULT NULL,"
|
"checksum TEXT DEFAULT NULL,"
|
||||||
"flags INTEGER DEFAULT 0,"
|
"flags INTEGER DEFAULT 0,"
|
||||||
"fwupd_version TEXT DEFAULT NULL,"
|
"metadata TEXT DEFAULT NULL,"
|
||||||
"guid_default TEXT DEFAULT NULL,"
|
"guid_default TEXT DEFAULT NULL,"
|
||||||
"version_old TEXT,"
|
"version_old TEXT,"
|
||||||
"version_new TEXT);", -1, &stmt, NULL);
|
"version_new TEXT);", -1, &stmt, NULL);
|
||||||
@ -217,12 +224,28 @@ fu_history_load (FuHistory *self, GError **error)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
_convert_hash_to_string (GHashTable *hash)
|
||||||
|
{
|
||||||
|
GString *str = g_string_new (NULL);
|
||||||
|
g_autoptr(GList) keys = g_hash_table_get_keys (hash);
|
||||||
|
for (GList *l = keys; l != NULL; l = l->next) {
|
||||||
|
const gchar *key = l->data;
|
||||||
|
const gchar *value = g_hash_table_lookup (hash, key);
|
||||||
|
if (str->len > 0)
|
||||||
|
g_string_append (str, ";");
|
||||||
|
g_string_append_printf (str, "%s=%s", key, value);
|
||||||
|
}
|
||||||
|
return g_string_free (str, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
fu_history_add_device (FuHistory *self, FuDevice *device, FwupdRelease *release, GError **error)
|
fu_history_add_device (FuHistory *self, FuDevice *device, FwupdRelease *release, GError **error)
|
||||||
{
|
{
|
||||||
FwupdDeviceFlags flags;
|
FwupdDeviceFlags flags;
|
||||||
const gchar *checksum = NULL;
|
const gchar *checksum = NULL;
|
||||||
gint rc;
|
gint rc;
|
||||||
|
g_autofree gchar *metadata = NULL;
|
||||||
g_autoptr(sqlite3_stmt) stmt = NULL;
|
g_autoptr(sqlite3_stmt) stmt = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (FU_IS_HISTORY (self), FALSE);
|
g_return_val_if_fail (FU_IS_HISTORY (self), FALSE);
|
||||||
@ -245,6 +268,9 @@ fu_history_add_device (FuHistory *self, FuDevice *device, FwupdRelease *release,
|
|||||||
flags &= ~FWUPD_DEVICE_FLAG_REGISTERED;
|
flags &= ~FWUPD_DEVICE_FLAG_REGISTERED;
|
||||||
flags &= ~FWUPD_DEVICE_FLAG_SUPPORTED;
|
flags &= ~FWUPD_DEVICE_FLAG_SUPPORTED;
|
||||||
|
|
||||||
|
/* metadata is stored as a simple string */
|
||||||
|
metadata = _convert_hash_to_string (fwupd_release_get_metadata (release));
|
||||||
|
|
||||||
/* add */
|
/* add */
|
||||||
rc = sqlite3_prepare_v2 (self->db,
|
rc = sqlite3_prepare_v2 (self->db,
|
||||||
"INSERT INTO history (device_id,"
|
"INSERT INTO history (device_id,"
|
||||||
@ -256,7 +282,7 @@ fu_history_add_device (FuHistory *self, FuDevice *device, FwupdRelease *release,
|
|||||||
"display_name,"
|
"display_name,"
|
||||||
"plugin,"
|
"plugin,"
|
||||||
"guid_default,"
|
"guid_default,"
|
||||||
"fwupd_version,"
|
"metadata,"
|
||||||
"device_created,"
|
"device_created,"
|
||||||
"device_modified,"
|
"device_modified,"
|
||||||
"version_old,"
|
"version_old,"
|
||||||
@ -278,7 +304,7 @@ fu_history_add_device (FuHistory *self, FuDevice *device, FwupdRelease *release,
|
|||||||
sqlite3_bind_text (stmt, 7, fu_device_get_name (device), -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 7, fu_device_get_name (device), -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text (stmt, 8, fu_device_get_plugin (device), -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 8, fu_device_get_plugin (device), -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text (stmt, 9, fu_device_get_guid_default (device), -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 9, fu_device_get_guid_default (device), -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_text (stmt, 10, VERSION, -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 10, metadata, -1, SQLITE_STATIC);
|
||||||
sqlite3_bind_int64 (stmt, 11, fu_device_get_created (device));
|
sqlite3_bind_int64 (stmt, 11, fu_device_get_created (device));
|
||||||
sqlite3_bind_int64 (stmt, 12, fu_device_get_modified (device));
|
sqlite3_bind_int64 (stmt, 12, fu_device_get_modified (device));
|
||||||
sqlite3_bind_text (stmt, 13, fu_device_get_version (device), -1, SQLITE_STATIC);
|
sqlite3_bind_text (stmt, 13, fu_device_get_version (device), -1, SQLITE_STATIC);
|
||||||
@ -390,7 +416,7 @@ fu_history_get_device (FuHistory *self, const gchar *device_id, GError **error)
|
|||||||
"display_name, "
|
"display_name, "
|
||||||
"filename, "
|
"filename, "
|
||||||
"flags, "
|
"flags, "
|
||||||
"fwupd_version, "
|
"metadata, "
|
||||||
"guid_default, "
|
"guid_default, "
|
||||||
"update_state, "
|
"update_state, "
|
||||||
"update_error, "
|
"update_error, "
|
||||||
@ -444,7 +470,7 @@ fu_history_get_devices (FuHistory *self, GError **error)
|
|||||||
"display_name, "
|
"display_name, "
|
||||||
"filename, "
|
"filename, "
|
||||||
"flags, "
|
"flags, "
|
||||||
"fwupd_version, "
|
"metadata, "
|
||||||
"guid_default, "
|
"guid_default, "
|
||||||
"update_state, "
|
"update_state, "
|
||||||
"update_error, "
|
"update_error, "
|
||||||
|
@ -381,6 +381,7 @@ fu_engine_history_func (void)
|
|||||||
g_assert_cmpint (fu_device_get_update_state (device2), ==, FWUPD_UPDATE_STATE_SUCCESS);
|
g_assert_cmpint (fu_device_get_update_state (device2), ==, FWUPD_UPDATE_STATE_SUCCESS);
|
||||||
g_assert_cmpstr (fu_device_get_update_error (device2), ==, NULL);
|
g_assert_cmpstr (fu_device_get_update_error (device2), ==, NULL);
|
||||||
fu_device_set_modified (device2, 1514338000);
|
fu_device_set_modified (device2, 1514338000);
|
||||||
|
g_hash_table_remove_all (fwupd_release_get_metadata (fu_device_get_release_default (device2)));
|
||||||
device_str = fu_device_to_string (device2);
|
device_str = fu_device_to_string (device2);
|
||||||
checksum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, blob_cab);
|
checksum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, blob_cab);
|
||||||
device_str_expected = g_strdup_printf (
|
device_str_expected = g_strdup_printf (
|
||||||
@ -397,9 +398,8 @@ fu_engine_history_func (void)
|
|||||||
" [Release]\n"
|
" [Release]\n"
|
||||||
" Version: 1.2.3\n"
|
" Version: 1.2.3\n"
|
||||||
" Checksum: SHA1(%s)\n"
|
" Checksum: SHA1(%s)\n"
|
||||||
" Vendor: %s\n"
|
|
||||||
" TrustFlags: none\n",
|
" TrustFlags: none\n",
|
||||||
checksum, VERSION);
|
checksum);
|
||||||
ret = fu_test_compare_lines (device_str, device_str_expected, &error);
|
ret = fu_test_compare_lines (device_str, device_str_expected, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
@ -481,6 +481,7 @@ fu_engine_history_error_func (void)
|
|||||||
g_assert_cmpstr (fu_device_get_update_error (device2), ==, error->message);
|
g_assert_cmpstr (fu_device_get_update_error (device2), ==, error->message);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
fu_device_set_modified (device2, 1514338000);
|
fu_device_set_modified (device2, 1514338000);
|
||||||
|
g_hash_table_remove_all (fwupd_release_get_metadata (fu_device_get_release_default (device2)));
|
||||||
device_str = fu_device_to_string (device2);
|
device_str = fu_device_to_string (device2);
|
||||||
checksum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, blob_cab);
|
checksum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, blob_cab);
|
||||||
device_str_expected = g_strdup_printf (
|
device_str_expected = g_strdup_printf (
|
||||||
@ -498,9 +499,8 @@ fu_engine_history_error_func (void)
|
|||||||
" [Release]\n"
|
" [Release]\n"
|
||||||
" Version: 1.2.3\n"
|
" Version: 1.2.3\n"
|
||||||
" Checksum: SHA1(%s)\n"
|
" Checksum: SHA1(%s)\n"
|
||||||
" Vendor: %s\n"
|
|
||||||
" TrustFlags: none\n",
|
" TrustFlags: none\n",
|
||||||
checksum, VERSION);
|
checksum);
|
||||||
ret = fu_test_compare_lines (device_str, device_str_expected, &error);
|
ret = fu_test_compare_lines (device_str, device_str_expected, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
@ -1214,6 +1214,7 @@ fu_history_func (void)
|
|||||||
fwupd_release_set_filename (release, "/var/lib/dave.cap"),
|
fwupd_release_set_filename (release, "/var/lib/dave.cap"),
|
||||||
fwupd_release_add_checksum (release, "abcdef");
|
fwupd_release_add_checksum (release, "abcdef");
|
||||||
fwupd_release_set_version (release, "3.0.2");
|
fwupd_release_set_version (release, "3.0.2");
|
||||||
|
fwupd_release_add_metadata_item (release, "FwupdVersion", VERSION);
|
||||||
ret = fu_history_add_device (history, device, release, &error);
|
ret = fu_history_add_device (history, device, release, &error);
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
@ -1252,7 +1253,7 @@ fu_history_func (void)
|
|||||||
g_assert (release != NULL);
|
g_assert (release != NULL);
|
||||||
g_assert_cmpstr (fwupd_release_get_version (release), ==, "3.0.2");
|
g_assert_cmpstr (fwupd_release_get_version (release), ==, "3.0.2");
|
||||||
g_assert_cmpstr (fwupd_release_get_filename (release), ==, "/var/lib/dave.cap");
|
g_assert_cmpstr (fwupd_release_get_filename (release), ==, "/var/lib/dave.cap");
|
||||||
g_assert_cmpstr (fwupd_release_get_vendor (release), ==, VERSION);
|
g_assert_cmpstr (fwupd_release_get_metadata_item (release, "FwupdVersion"), ==, VERSION);
|
||||||
checksums = fwupd_release_get_checksums (release);
|
checksums = fwupd_release_get_checksums (release);
|
||||||
g_assert (checksums != NULL);
|
g_assert (checksums != NULL);
|
||||||
g_assert_cmpint (checksums->len, ==, 1);
|
g_assert_cmpint (checksums->len, ==, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user