fix(landerctl): don't fail when libmagic fails
ci/woodpecker/push/docker Pipeline was successful
Details
ci/woodpecker/push/docker Pipeline was successful
Details
parent
881f2defbe
commit
e3c3f3b90a
|
@ -7,7 +7,7 @@ SRC_DIR = src
|
||||||
TEST_DIR = test
|
TEST_DIR = test
|
||||||
|
|
||||||
INC_DIRS = include
|
INC_DIRS = include
|
||||||
LIBS = magic curl
|
LIBS ?= magic curl
|
||||||
LIB_DIRS =
|
LIB_DIRS =
|
||||||
|
|
||||||
# -MMD: generate a .d file for every source file. This file can be imported by
|
# -MMD: generate a .d file for every source file. This file can be imported by
|
||||||
|
|
|
@ -102,11 +102,21 @@ landerctl_err landerctl_post_file(landerctl_ctx *ctx) {
|
||||||
curl_easy_setopt(ctx->curl, CURLOPT_NOPROGRESS, 0L);
|
curl_easy_setopt(ctx->curl, CURLOPT_NOPROGRESS, 0L);
|
||||||
|
|
||||||
magic_t cookie = magic_open(MAGIC_MIME_TYPE);
|
magic_t cookie = magic_open(MAGIC_MIME_TYPE);
|
||||||
magic_load(cookie, NULL);
|
|
||||||
const char *mime_type = magic_file(cookie, ctx->arg);
|
|
||||||
|
|
||||||
char content_type_header[strlen(mime_type) + 24];
|
if (magic_load(cookie, NULL) == 0) {
|
||||||
sprintf(content_type_header, "X-Lander-Content-Type: %s", mime_type);
|
const char *mime_type = magic_file(cookie, ctx->arg);
|
||||||
|
|
||||||
|
if (mime_type != NULL) {
|
||||||
|
char content_type_header[strlen(mime_type) + 24];
|
||||||
|
sprintf(content_type_header, "X-Lander-Content-Type: %s", mime_type);
|
||||||
|
|
||||||
|
ctx->headers = curl_slist_append(ctx->headers, content_type_header);
|
||||||
|
} else {
|
||||||
|
printf("Couldn't determine mime type; skipping Content-Type header");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("Couldn't load magic file; skipping Content-Type header");
|
||||||
|
}
|
||||||
|
|
||||||
char s[strlen(ctx->arg) + 1];
|
char s[strlen(ctx->arg) + 1];
|
||||||
strcpy(s, ctx->arg);
|
strcpy(s, ctx->arg);
|
||||||
|
@ -115,7 +125,6 @@ landerctl_err landerctl_post_file(landerctl_ctx *ctx) {
|
||||||
char filename_header[strlen(base_name) + 20];
|
char filename_header[strlen(base_name) + 20];
|
||||||
sprintf(filename_header, "X-Lander-Filename: %s", base_name);
|
sprintf(filename_header, "X-Lander-Filename: %s", base_name);
|
||||||
|
|
||||||
ctx->headers = curl_slist_append(ctx->headers, content_type_header);
|
|
||||||
ctx->headers = curl_slist_append(ctx->headers, filename_header);
|
ctx->headers = curl_slist_append(ctx->headers, filename_header);
|
||||||
|
|
||||||
return landerctl_err_ok;
|
return landerctl_err_ok;
|
||||||
|
|
Loading…
Reference in New Issue