Skip to content

Commit

Permalink
chore: explicit error for no files in zephyr-image-update-module
Browse files Browse the repository at this point in the history
In order to check the error, we needed a way to get the filename. Since
we don't have access to the update state data, we set it when reading
the manifest.

Ticket: MEN-7804

Signed-off-by: Daniel Skinstad Drabitzius <[email protected]>
  • Loading branch information
danielskinstad committed Jan 31, 2025
1 parent 140a71a commit 3aeaa60
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/mender-artifact.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,13 @@ mender_artifact_get_device_type(mender_artifact_ctx_t *ctx, const char **device_
return MENDER_FAIL;
}

static char *artifact_file = NULL;

char *
mender_artifact_get_filename(void) {
return artifact_file;
}

static mender_err_t
artifact_read_manifest(mender_artifact_ctx_t *ctx) {

Expand Down Expand Up @@ -757,6 +764,9 @@ artifact_read_manifest(mender_artifact_ctx_t *ctx) {
const char *checksum_str = line;
const char *filename = separator + 2;

/* Store the filename in the artifact */
artifact_file = (char *)filename;

/* We do not support compressed artifacts */
if (mender_utils_strbeginswith(filename, "header.tar") && is_compressed(filename)) {
mender_log_error("Artifact compression is not supported");
Expand Down
9 changes: 9 additions & 0 deletions core/src/mender-zephyr-image-update-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* limitations under the License.
*/

#include "mender-artifact.h"
#include "mender-client.h"
#include "mender-flash.h"
#include "mender-log.h"
Expand Down Expand Up @@ -136,6 +137,14 @@ mender_zephyr_image_set_pending_image(MENDER_NDEBUG_UNUSED mender_update_state_t
assert(MENDER_UPDATE_STATE_INSTALL == state);
mender_err_t ret;

#ifdef CONFIG_MENDER_FULL_PARSE_ARTIFACT
const char *artifact_filename = mender_artifact_get_filename();
if (NULL == mender_artifact_get_filename() || artifact_filename[0] == '\0') {
mender_log_error("No file in artifact");
return MENDER_FAIL;
}
#endif

if (NULL == mcu_boot_flash_handle) {
mender_log_error("Set pending image requested but handle is cleared");
return MENDER_FAIL;
Expand Down
7 changes: 7 additions & 0 deletions include/mender-artifact.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ mender_err_t mender_artifact_get_ctx(mender_artifact_ctx_t **ctx);
*/
mender_err_t mender_artifact_process_data(mender_artifact_ctx_t *ctx, void *input_data, size_t input_length, mender_artifact_download_data_t *dl_data);

#ifdef CONFIG_MENDER_FULL_PARSE_ARTIFACT
/**
* @brief Function used to get the filename in artifact
*/
char *mender_artifact_get_filename(void);
#endif

/**
* @brief Do integrity checks by comparing the manifest checksums to the computed ones
* @param ctx Artifact context
Expand Down

0 comments on commit 3aeaa60

Please sign in to comment.