From d66fefa1d445c5f5e3ba9d658a052ededcf06c22 Mon Sep 17 00:00:00 2001 From: ngn Date: Tue, 16 Jul 2024 16:04:21 +0300 Subject: [PATCH] fix: add missing error checking for sync command --- include/error.h | 1 + locale/tr/LC_MESSAGES/libmp.po | 6 +++++- src/ctx/sync.c | 11 +++++++++++ src/error.c | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/error.h b/include/error.h index a1d92bc..3f486c3 100644 --- a/include/error.h +++ b/include/error.h @@ -139,6 +139,7 @@ typedef enum lm_error { LM_ERR_FileHashFail = 131, LM_ERR_FileHashNoMatch = 132, LM_ERR_InfoNotLoaded = 133, + LM_ERR_NoPools = 134, } lm_error_t; typedef struct lm_error_desc { diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index 34bf5fa..7a83c6f 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-07-14 21:05+0300\n" +"POT-Creation-Date: 2024-07-16 16:03+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -587,3 +587,7 @@ msgstr "" #, fuzzy msgid "pool info is not loaded" msgstr "URL hostname is too large" + +#: src/error.c:159 +msgid "pool list is empty" +msgstr "" diff --git a/src/ctx/sync.c b/src/ctx/sync.c index 5226422..2f79699 100644 --- a/src/ctx/sync.c +++ b/src/ctx/sync.c @@ -26,6 +26,16 @@ bool __lm_ctx_sync_callback(char *path, size_t current, size_t total, void *data } size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callback, void *data){ + if(NULL == ctx) { + lm_error_set(LM_ERR_ArgNULL); + return -1; + } + + if(NULL == ctx->pools){ + lm_error_set(LM_ERR_NoPools); + return -1; + } + struct __lm_ctx_sync_cb_data cbdata = { .ctx = ctx, .callback = callback, @@ -41,6 +51,7 @@ size_t lm_ctx_sync(lm_ctx_t *ctx, bool do_update, lm_ctx_sync_callback_t callbac if(lm_pool_path_is_empty(cur)){ pdebug(__func__, "(%s) failed to load info, pool paths are empty", cur->name); + lm_error_set(LM_ERR_PoolPathsEmpty); goto next_info; } diff --git a/src/error.c b/src/error.c index 2d3c685..34932e1 100644 --- a/src/error.c +++ b/src/error.c @@ -156,6 +156,7 @@ void lm_error_set(lm_error_t code, ...) { {.code = LM_ERR_FileHashFail, .desc = _("failed to get hash of %s: %s") }, {.code = LM_ERR_FileHashNoMatch, .desc = _("file hash does not match for %s") }, {.code = LM_ERR_InfoNotLoaded, .desc = _("pool info is not loaded") }, + {.code = LM_ERR_NoPools, .desc = _("pool list is empty") }, }; char *fmt = NULL;