From 914f636aa6029fe957f9c3b04f7e5e352e0b7d49 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Tue, 31 Jan 2023 08:44:27 +0000 Subject: [PATCH] Return an error when the pending db could not be updated --- src/fu-history.c | 14 +++++++++++--- src/fu-self-test.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/fu-history.c b/src/fu-history.c index 4f2d1735d..c08e25d32 100644 --- a/src/fu-history.c +++ b/src/fu-history.c @@ -629,10 +629,18 @@ fu_history_modify_device(FuHistory *self, FuDevice *device, GError **error) SQLITE_STATIC); sqlite3_bind_int64(stmt, 7, fu_device_get_modified(device)); - return fu_history_stmt_exec(self, stmt, NULL, error); -#else - return TRUE; + if (!fu_history_stmt_exec(self, stmt, NULL, error)) + return FALSE; + if (sqlite3_changes(self->db) == 0) { + g_set_error(error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "no device %s", + fu_device_get_id(device)); + return FALSE; + } #endif + return TRUE; } /** diff --git a/src/fu-self-test.c b/src/fu-self-test.c index edc040eb7..ac4400079 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -1914,6 +1914,35 @@ fu_engine_install_duration_func(gconstpointer user_data) g_assert_cmpint(fwupd_release_get_install_duration(rel), ==, 120); } +static void +fu_engine_history_modify_func(gconstpointer user_data) +{ + FuTest *self = (FuTest *)user_data; + gboolean ret; + g_autoptr(FuDevice) device = fu_device_new(self->ctx); + g_autoptr(FuHistory) history = fu_history_new(); + g_autoptr(FuRelease) release = fu_release_new(); + g_autoptr(GError) error = NULL; + + /* add a new entry */ + fu_device_set_id(device, "foobarbaz"); + fu_history_remove_device(history, device, NULL); + ret = fu_history_add_device(history, device, FWUPD_RELEASE(release), &error); + g_assert_no_error(error); + g_assert_true(ret); + + /* try to modify something that does exist */ + ret = fu_history_modify_device(history, device, &error); + g_assert_no_error(error); + g_assert_true(ret); + + /* does not exist */ + fu_device_set_id(device, "DOES-NOT-EXIST"); + ret = fu_history_modify_device(history, device, &error); + g_assert_false(ret); + g_assert_error(error, FWUPD_ERROR, FWUPD_ERROR_NOT_FOUND); +} + static void fu_engine_history_func(gconstpointer user_data) { @@ -4892,6 +4921,7 @@ main(int argc, char **argv) self, fu_engine_multiple_rels_func); g_test_add_data_func("/fwupd/engine{history-success}", self, fu_engine_history_func); + g_test_add_data_func("/fwupd/engine{history-modify}", self, fu_engine_history_modify_func); g_test_add_data_func("/fwupd/engine{history-error}", self, fu_engine_history_error_func); if (g_test_slow()) { g_test_add_data_func("/fwupd/device-list{replug-auto}",