diff --git a/src/fu-main.c b/src/fu-main.c index ae1d5aca0..e3af0e327 100644 --- a/src/fu-main.c +++ b/src/fu-main.c @@ -1704,6 +1704,19 @@ fu_main_daemon_method_call (GDBusConnection *connection, const gchar *sender, return; } + /* ensure the unique ID is set */ + if (fwupd_result_get_unique_id (FWUPD_RESULT (item->device)) == NULL) { + g_autofree gchar *id = NULL; + FwupdResult *res = FWUPD_RESULT (item->device); + id = as_utils_unique_id_build (AS_APP_SCOPE_SYSTEM, + AS_BUNDLE_KIND_UNKNOWN, + NULL, + AS_APP_KIND_FIRMWARE, + fwupd_result_get_device_name (res), + fwupd_result_get_device_version (res)); + fwupd_result_set_unique_id (res, id); + } + /* success */ val = fwupd_result_to_data (FWUPD_RESULT (item->device), "(a{sv})"); fu_main_invocation_return_value (priv, invocation, val); diff --git a/src/fu-pending.c b/src/fu-pending.c index 8a425f26a..e28b79220 100644 --- a/src/fu-pending.c +++ b/src/fu-pending.c @@ -82,6 +82,7 @@ fu_pending_load (FuPending *pending, GError **error) sqlite3_free (error_msg); statement = "CREATE TABLE pending (" "device_id TEXT PRIMARY KEY," + "unique_id TEXT," "state INTEGER DEFAULT 0," "timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL," "error TEXT," @@ -129,6 +130,17 @@ fu_pending_load (FuPending *pending, GError **error) sqlite3_exec (priv->db, statement, NULL, NULL, NULL); } + /* check pending has unique_id (since 0.7.3) */ + rc = sqlite3_exec (priv->db, + "SELECT unique_id FROM pending LIMIT 1", + NULL, NULL, &error_msg); + if (rc != SQLITE_OK) { + g_debug ("FuPending: altering table to repair: %s", error_msg); + sqlite3_free (error_msg); + statement = "ALTER TABLE pending ADD COLUMN unique_id TEXT;"; + sqlite3_exec (priv->db, statement, NULL, NULL, NULL); + } + return TRUE; } @@ -151,14 +163,16 @@ fu_pending_add_device (FuPending *pending, FwupdResult *res, GError **error) g_debug ("FuPending: add device %s", fwupd_result_get_device_id (res)); statement = sqlite3_mprintf ("INSERT INTO pending (device_id," + "unique_id," "state," "filename," "display_name," "provider," "version_old," "version_new) " - "VALUES ('%q','%i','%q','%q','%q','%q','%q')", + "VALUES ('%q','%q','%i','%q','%q','%q','%q','%q')", fwupd_result_get_device_id (res), + fwupd_result_get_unique_id (res), FWUPD_UPDATE_STATE_PENDING, fwupd_result_get_update_filename (res), fwupd_result_get_device_name (res), @@ -241,6 +255,10 @@ fu_pending_device_sqlite_cb (void *data, fwupd_result_set_device_id (res, argv[i]); continue; } + if (g_strcmp0 (col_name[i], "unique_id") == 0) { + fwupd_result_set_unique_id (res, argv[i]); + continue; + } if (g_strcmp0 (col_name[i], "filename") == 0) { fwupd_result_set_update_filename (res, argv[i]); continue;