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
|
||||
|
||||
INC_DIRS = include
|
||||
LIBS = magic curl
|
||||
LIBS ?= magic curl
|
||||
LIB_DIRS =
|
||||
|
||||
# -MMD: generate a .d file for every source file. This file can be imported by
|
||||
|
|
|
@ -102,12 +102,22 @@ landerctl_err landerctl_post_file(landerctl_ctx *ctx) {
|
|||
curl_easy_setopt(ctx->curl, CURLOPT_NOPROGRESS, 0L);
|
||||
|
||||
magic_t cookie = magic_open(MAGIC_MIME_TYPE);
|
||||
magic_load(cookie, NULL);
|
||||
|
||||
if (magic_load(cookie, NULL) == 0) {
|
||||
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];
|
||||
strcpy(s, ctx->arg);
|
||||
const char *base_name = basename(s);
|
||||
|
@ -115,7 +125,6 @@ landerctl_err landerctl_post_file(landerctl_ctx *ctx) {
|
|||
char filename_header[strlen(base_name) + 20];
|
||||
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);
|
||||
|
||||
return landerctl_err_ok;
|
||||
|
|
Loading…
Reference in New Issue