trivial: Ensure a historical error message is cleared on success

This commit is contained in:
Richard Hughes 2018-01-12 16:45:30 +00:00
parent d949d961e8
commit 7984310a65
3 changed files with 15 additions and 17 deletions

View File

@ -1539,11 +1539,6 @@ fu_engine_install (FuEngine *self,
g_autoptr(GError) error_attach = NULL; g_autoptr(GError) error_attach = NULL;
/* save to database */ /* 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, if (!fu_history_set_device_error (self->history,
fu_device_get_id (device), fu_device_get_id (device),
error_local->message, 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)) if (!fu_plugin_runner_get_results (plugin, dev, error))
return FALSE; return FALSE;
if (fu_device_get_update_state (dev) != FWUPD_UPDATE_STATE_NEEDS_REBOOT) { 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, if (!fu_history_set_device_error (self->history,
fu_device_get_id (dev), fu_device_get_id (dev),
fu_device_get_update_error (dev), fu_device_get_update_error (dev),

View File

@ -541,8 +541,14 @@ fu_history_set_device_state (FuHistory *self,
if (!fu_history_load (self, error)) if (!fu_history_load (self, error))
return FALSE; return FALSE;
/* clear the error too */
g_debug ("FuHistory: set update-state of %s to %s", g_debug ("FuHistory: set update-state of %s to %s",
device_id, fwupd_update_state_to_string (update_state)); 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, rc = sqlite3_prepare_v2 (self->db,
"UPDATE history SET update_state = ?1 WHERE " "UPDATE history SET update_state = ?1 WHERE "
"device_id = ?2;", -1, &stmt, NULL); "device_id = ?2;", -1, &stmt, NULL);
@ -573,7 +579,15 @@ fu_history_set_device_error (FuHistory *self,
if (!fu_history_load (self, error)) if (!fu_history_load (self, error))
return FALSE; return FALSE;
/* automatically set the state */
g_debug ("FuHistory: set error to %s: %s", device_id, error_msg); 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, rc = sqlite3_prepare_v2 (self->db,
"UPDATE history SET update_error = ?1 WHERE " "UPDATE history SET update_error = ?1 WHERE "
"device_id = ?2;", -1, &stmt, NULL); "device_id = ?2;", -1, &stmt, NULL);

View File

@ -1224,12 +1224,6 @@ fu_history_func (void)
g_assert (g_file_test (filename, G_FILE_TEST_EXISTS)); g_assert (g_file_test (filename, G_FILE_TEST_EXISTS));
/* add some extra data */ /* 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, ret = fu_history_set_device_error (history,
"2ba16d10df45823dd4494ff10a0bfccfef512c9d", "2ba16d10df45823dd4494ff10a0bfccfef512c9d",
"word", "word",
@ -1245,7 +1239,7 @@ fu_history_func (void)
g_assert_cmpstr (fu_device_get_id (device), ==, "2ba16d10df45823dd4494ff10a0bfccfef512c9d"); g_assert_cmpstr (fu_device_get_id (device), ==, "2ba16d10df45823dd4494ff10a0bfccfef512c9d");
g_assert_cmpstr (fu_device_get_name (device), ==, "ColorHug"); g_assert_cmpstr (fu_device_get_name (device), ==, "ColorHug");
g_assert_cmpstr (fu_device_get_version (device), ==, "3.0.1"); 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_update_error (device), ==, "word");
g_assert_cmpstr (fu_device_get_guid_default (device), ==, "827edddd-9bb6-5632-889f-2c01255503da"); 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); g_assert_cmpint (fu_device_get_flags (device), ==, FWUPD_DEVICE_FLAG_INTERNAL);