Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEN-7804 - handle no files in artifact #131

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions core/src/mender-artifact.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ static mender_err_t artifact_read_version(mender_artifact_ctx_t *ctx);
/**
* @brief Read header-info file of the artifact
* @param ctx Artifact context
* @param dl_data Download data for the artifact
* @return MENDER_DONE if the data have been parsed and payloads retrieved, MENDER_OK if there is not enough data to parse, error code if an error occurred
*/
static mender_err_t artifact_read_header_info(mender_artifact_ctx_t *ctx);
static mender_err_t artifact_read_header_info(mender_artifact_ctx_t *ctx, mender_artifact_download_data_t *dl_data);

#ifdef CONFIG_MENDER_FULL_PARSE_ARTIFACT
/**
Expand Down Expand Up @@ -423,7 +424,7 @@ mender_artifact_process_data(mender_artifact_ctx_t *ctx, void *input_data, size_
} else if (StringEqual(ctx->file.name, "header.tar/header-info")) {

/* Read header-info file */
ret = artifact_read_header_info(ctx);
ret = artifact_read_header_info(ctx, dl_data);

} else if ((true == mender_utils_strbeginswith(ctx->file.name, "header.tar/headers"))
&& (true == mender_utils_strendswith(ctx->file.name, "meta-data"))) {
Expand Down Expand Up @@ -838,7 +839,7 @@ artifact_parse_provides_depends(cJSON *json_provides_depends, mender_key_value_l
#endif

static mender_err_t
artifact_read_header_info(mender_artifact_ctx_t *ctx) {
artifact_read_header_info(mender_artifact_ctx_t *ctx, mender_artifact_download_data_t *dl_data) {

assert(NULL != ctx);
cJSON *object = NULL;
Expand Down Expand Up @@ -874,6 +875,21 @@ artifact_read_header_info(mender_artifact_ctx_t *ctx) {
ret = MENDER_FAIL;
goto END;
}
const char *payload_type = ctx->payloads.values[index].type;
/* Choose update module */
dl_data->update_module = mender_update_module_get(payload_type);
if (NULL == dl_data->update_module) {
/* Content is not supported by the mender-mcu-client */
mender_log_error("Unable to handle artifact type '%s'", payload_type);
ret = MENDER_FAIL;
goto END;
}
/* Add the payload type to deployment data */
if (MENDER_OK != mender_deployment_data_add_payload_type(dl_data->deployment, payload_type)) {
/* Error already logged */
ret = MENDER_FAIL;
goto END;
}
} else {
mender_log_error("Invalid header-info file");
ret = MENDER_FAIL;
Expand Down Expand Up @@ -1184,20 +1200,6 @@ artifact_read_data_prepare(mender_artifact_ctx_t *ctx, mender_artifact_download_

const char *payload_type = ctx->payloads.values[index].type;

/* Choose update module */
dl_data->update_module = mender_update_module_get(payload_type);
if (NULL == dl_data->update_module) {
/* Content is not supported by the mender-mcu-client */
mender_log_error("Unable to handle artifact type '%s'", payload_type);
return MENDER_FAIL;
}

/* Add the payload type to deployment data */
if (MENDER_OK != mender_deployment_data_add_payload_type(dl_data->deployment, payload_type)) {
/* Error already logged */
return MENDER_FAIL;
}

/* Retrieve ID and artifact name */
if (MENDER_OK != mender_deployment_data_get_id(dl_data->deployment, &(mdata_cache->deployment_id))) {
mender_log_error("Unable to get ID from the deployment data");
Expand Down
10 changes: 10 additions & 0 deletions core/src/mender-zephyr-image-update-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/
static void *mcu_boot_flash_handle = NULL;

static bool artifact_had_payload;

/**
* @brief Callback function to be invoked to perform the treatment of the data from the artifact type "zephyr-image"
* @return MENDER_OK if the function succeeds, error code if an error occurred
Expand Down Expand Up @@ -126,6 +128,7 @@ mender_zephyr_image_download_artifact_flash_callback(MENDER_NDEBUG_UNUSED mender
}
}

artifact_had_payload = true;
END:

return ret;
Expand All @@ -136,6 +139,12 @@ mender_zephyr_image_set_pending_image(MENDER_NDEBUG_UNUSED mender_update_state_t
assert(MENDER_UPDATE_STATE_INSTALL == state);
mender_err_t ret;

if (!artifact_had_payload) {
mender_log_error("No payload in artifact");
return MENDER_FAIL;
}
artifact_had_payload = false;

if (NULL == mcu_boot_flash_handle) {
mender_log_error("Set pending image requested but handle is cleared");
return MENDER_FAIL;
Expand All @@ -157,6 +166,7 @@ mender_zephyr_image_abort_deployment(MENDER_NDEBUG_UNUSED mender_update_state_t
mender_log_error("Unable to abort deployment");
return ret;
}
artifact_had_payload = false;
return MENDER_OK;
}

Expand Down