diff --git a/src/fu-engine.c b/src/fu-engine.c index 064b43457..151f2c9c2 100644 --- a/src/fu-engine.c +++ b/src/fu-engine.c @@ -1539,11 +1539,6 @@ fu_engine_install (FuEngine *self, g_autoptr(GError) error_attach = NULL; /* save to database */ - if (!fu_history_set_device_state (self->history, - fu_device_get_id (device), - FWUPD_UPDATE_STATE_FAILED, - error)) - return FALSE; if (!fu_history_set_device_error (self->history, fu_device_get_id (device), error_local->message, @@ -3384,11 +3379,6 @@ fu_engine_update_history_device (FuEngine *self, FuDevice *dev_history, GError * if (!fu_plugin_runner_get_results (plugin, dev, error)) return FALSE; if (fu_device_get_update_state (dev) != FWUPD_UPDATE_STATE_NEEDS_REBOOT) { - if (!fu_history_set_device_state (self->history, - fu_device_get_id (dev), - fu_device_get_update_state (dev), - error)) - return FALSE; if (!fu_history_set_device_error (self->history, fu_device_get_id (dev), fu_device_get_update_error (dev), diff --git a/src/fu-history.c b/src/fu-history.c index 48375793a..a60256558 100644 --- a/src/fu-history.c +++ b/src/fu-history.c @@ -541,8 +541,14 @@ fu_history_set_device_state (FuHistory *self, if (!fu_history_load (self, error)) return FALSE; + /* clear the error too */ g_debug ("FuHistory: set update-state of %s to %s", device_id, fwupd_update_state_to_string (update_state)); + if (update_state != FWUPD_UPDATE_STATE_FAILED) { + g_debug ("FuHistory: ensuring error-msg is NULL"); + if (!fu_history_set_device_error (self, device_id, NULL, error)) + return FALSE; + } rc = sqlite3_prepare_v2 (self->db, "UPDATE history SET update_state = ?1 WHERE " "device_id = ?2;", -1, &stmt, NULL); @@ -573,7 +579,15 @@ fu_history_set_device_error (FuHistory *self, if (!fu_history_load (self, error)) return FALSE; + /* automatically set the state */ g_debug ("FuHistory: set error to %s: %s", device_id, error_msg); + if (error_msg != NULL) { + g_debug ("FuHistory: ensuring update-state is failed"); + if (!fu_history_set_device_state (self, device_id, + FWUPD_UPDATE_STATE_FAILED, + error)) + return FALSE; + } rc = sqlite3_prepare_v2 (self->db, "UPDATE history SET update_error = ?1 WHERE " "device_id = ?2;", -1, &stmt, NULL); diff --git a/src/fu-self-test.c b/src/fu-self-test.c index 12004ae6e..cb92c6a5a 100644 --- a/src/fu-self-test.c +++ b/src/fu-self-test.c @@ -1224,12 +1224,6 @@ fu_history_func (void) g_assert (g_file_test (filename, G_FILE_TEST_EXISTS)); /* add some extra data */ - ret = fu_history_set_device_state (history, - "2ba16d10df45823dd4494ff10a0bfccfef512c9d", - FWUPD_UPDATE_STATE_PENDING, - &error); - g_assert_no_error (error); - g_assert (ret); ret = fu_history_set_device_error (history, "2ba16d10df45823dd4494ff10a0bfccfef512c9d", "word", @@ -1245,7 +1239,7 @@ fu_history_func (void) g_assert_cmpstr (fu_device_get_id (device), ==, "2ba16d10df45823dd4494ff10a0bfccfef512c9d"); g_assert_cmpstr (fu_device_get_name (device), ==, "ColorHug"); g_assert_cmpstr (fu_device_get_version (device), ==, "3.0.1"); - g_assert_cmpint (fu_device_get_update_state (device), ==, FWUPD_UPDATE_STATE_PENDING); + g_assert_cmpint (fu_device_get_update_state (device), ==, FWUPD_UPDATE_STATE_FAILED); g_assert_cmpstr (fu_device_get_update_error (device), ==, "word"); g_assert_cmpstr (fu_device_get_guid_default (device), ==, "827edddd-9bb6-5632-889f-2c01255503da"); g_assert_cmpint (fu_device_get_flags (device), ==, FWUPD_DEVICE_FLAG_INTERNAL);