Return an error when the pending db could not be updated

This commit is contained in:
Richard Hughes 2023-01-31 08:44:27 +00:00
parent 3df5bf7bde
commit 914f636aa6
2 changed files with 41 additions and 3 deletions

View File

@ -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;
}
/**

View File

@ -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}",