From 6708ba8937e2ffd652927bf1cf15eb3e41ae7985 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Fri, 23 Sep 2022 10:26:24 +0800 Subject: [PATCH] chore: upload license to persistence directory --- plugins/restful/license_handle.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/restful/license_handle.c b/plugins/restful/license_handle.c index bb92a076..6f8239a4 100644 --- a/plugins/restful/license_handle.c +++ b/plugins/restful/license_handle.c @@ -19,6 +19,7 @@ #define _POSIX_C_SOURCE 200809L #include +#include #include #include @@ -43,10 +44,34 @@ int get_plugin_names(const license_t *lic, UT_array *plugin_names); static inline char *get_license_path() { char *s = NULL; - neu_asprintf(&s, "%s/%s", g_config_dir, LICENSE_FNAME); + neu_asprintf(&s, "persistence/%s", LICENSE_FNAME); return s; } +static inline char *get_license_path_or_fallback() +{ + struct stat statbuf = {}; + char * license_path = get_license_path(); + if (NULL == license_path) { + return NULL; + } + + if (0 == stat(license_path, &statbuf)) { + return license_path; + } + + nlog_warn("license `%s` not found", license_path); + free(license_path); + license_path = NULL; + + neu_asprintf(&license_path, "%s/%s", g_config_dir, LICENSE_FNAME); + if (NULL != license_path) { + nlog_warn("license fallback to `%s`", license_path); + } + + return license_path; +} + void handle_get_license(nng_aio *aio) { int rv = 0; @@ -65,7 +90,7 @@ void handle_get_license(nng_aio *aio) utarray_new(plugin_names, &ut_ptr_icd); - license_path = get_license_path(); + license_path = get_license_path_or_fallback(); if (NULL == license_path) { rv = NEU_ERR_EINTERNAL; goto final;