From ad332dc725e86b9e09b6aac5c5c5094d35152138 Mon Sep 17 00:00:00 2001 From: Vyacheslav Yurkov Date: Fri, 7 Jul 2023 21:26:40 +0200 Subject: [PATCH] hawkbit-client: Return proper status on download-only SUCCESS would translate from DDI state to action state "Downloaded", which is exactly what hawkbit expects in case of download-only deployemnt. Ref #159 Signed-off-by: Vyacheslav Yurkov --- include/hawkbit-client.h | 1 + src/hawkbit-client.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/hawkbit-client.h b/include/hawkbit-client.h index 91e33e32..200c8df6 100644 --- a/include/hawkbit-client.h +++ b/include/hawkbit-client.h @@ -90,6 +90,7 @@ typedef struct Artifact_ { gchar *download_url; /**< download URL of software bundle file */ gchar *feedback_url; /**< URL status feedback should be sent to */ gchar *sha1; /**< sha1 checksum of software bundle file */ + gchar *maintenance_window; /**< maintenance flag, possible values: available, unavailable, null */ gboolean do_install; /**< whether the installation should be started or not */ } Artifact; diff --git a/src/hawkbit-client.c b/src/hawkbit-client.c index b7fc162b..ffe932e6 100644 --- a/src/hawkbit-client.c +++ b/src/hawkbit-client.c @@ -914,6 +914,17 @@ static gpointer download_thread(gpointer data) } g_mutex_lock(&active_action->mutex); + // skip installation if hawkBit asked us to do so + if (!artifact->do_install && + (!artifact->maintenance_window || g_strcmp0(artifact->maintenance_window, "available") == 0)) { + active_action->state = ACTION_STATE_SUCCESS; + if (!feedback(artifact->feedback_url, active_action->id, "File checksum OK.", "success", + "downloaded", &feedback_error)) + g_warning("%s", feedback_error->message); + + g_mutex_unlock(&active_action->mutex); + return GINT_TO_POINTER(TRUE); + } if (!feedback_progress(artifact->feedback_url, active_action->id, "File checksum OK.", &error)) { g_warning("%s", error->message); @@ -1064,6 +1075,7 @@ static gboolean process_deployment(JsonNode *req_root, GError **error) // handle deployment.maintenanceWindow (only available if maintenance window is defined) maintenance_window = json_get_string(resp_root, "$.deployment.maintenanceWindow", NULL); + artifact->maintenance_window = g_strdup(maintenance_window); maintenance_msg = maintenance_window ? g_strdup_printf(" (maintenance window is '%s')", maintenance_window) : g_strdup(""); @@ -1486,6 +1498,7 @@ void artifact_free(Artifact *artifact) g_free(artifact->download_url); g_free(artifact->feedback_url); g_free(artifact->sha1); + g_free(artifact->maintenance_window); g_free(artifact); }