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

Explicit error for compressed Artifacts #84

Merged
merged 2 commits into from
Sep 30, 2024
Merged
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
20 changes: 20 additions & 0 deletions core/src/mender-artifact.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ mender_artifact_get_ctx(mender_artifact_ctx_t **ctx) {
return MENDER_OK;
}

static bool
is_compressed(const char *filename) {

static const char *compression_suffixes[] = { ".gz", ".xz", ".zst", NULL };

for (size_t i = 0; NULL != compression_suffixes[i]; i++) {
if (mender_utils_strendwith(filename, compression_suffixes[i])) {
return true;
}
}

return false;
}

mender_err_t
mender_artifact_process_data(mender_artifact_ctx_t *ctx,
void *input_data,
Expand All @@ -204,6 +218,12 @@ mender_artifact_process_data(mender_artifact_ctx_t *ctx,
/* Parse data */
do {

/* We do not support compressed artifacts */
if (is_compressed(ctx->file.name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this derived from the URL?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file name? That comes from the payload

mender_log_error("Artifact compression is not supported");
return MENDER_FAIL;
}

/* Treatment depending of the stream state */
if (MENDER_ARTIFACT_STREAM_STATE_PARSING_HEADER == ctx->stream_state) {

Expand Down
21 changes: 12 additions & 9 deletions core/src/mender-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,15 +1170,18 @@ mender_client_download_artifact_callback(char *type, cJSON *meta_data, char *fil
mender_err_t ret = MENDER_FAIL;

#if CONFIG_MENDER_LOG_LEVEL >= MENDER_LOG_LEVEL_INF
static size_t download_progress = 0;
/* New update */
if (0 == index) {
download_progress = 0;
}
/* Update every 10% */
if (((index * 10) / size) > download_progress) {
download_progress = (index * 10) / size;
mender_log_info("Downloading '%s' %zu0%%... [%zu/%zu]", type, download_progress, index, size);
if (size > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

static size_t download_progress = 0;
/* New update */
if (0 == index) {
download_progress = 0;
}

/* Update every 10% */
if (((index * 10) / size) > download_progress) {
download_progress = (index * 10) / size;
mender_log_info("Downloading '%s' %zu0%%... [%zu/%zu]", type, download_progress, index, size);
}
}
#endif

Expand Down