From afa81c7284010d03af1c57cc3554cdac60b981eb Mon Sep 17 00:00:00 2001 From: ngn Date: Tue, 16 Jul 2024 19:33:18 +0300 Subject: [PATCH] fix: add some missing error checking with install operation --- locale/tr/LC_MESSAGES/libmp.po | 2 +- src/ctx/install.c | 15 ++++++++++----- src/util.c | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index 7a83c6f..7db0e02 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-16 16:03+0300\n" +"POT-Creation-Date: 2024-07-16 19:29+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/src/ctx/install.c b/src/ctx/install.c index 5c8c6a0..33401aa 100644 --- a/src/ctx/install.c +++ b/src/ctx/install.c @@ -170,11 +170,6 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call return false; } - if(lm_ctx_database_is_installed(ctx, pkg, false)){ - lm_error_set(LM_ERR_PkgAlreadyInstalled); - return false; - } - if(NULL == ctx->root){ lm_error_set(LM_ERR_CtxRootNULL); return false; @@ -188,6 +183,16 @@ bool lm_ctx_install(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_install_callback_t call if(!lm_ctx_database_init(ctx)) return false; // error set by function + if(lm_ctx_database_is_installed(ctx, pkg, false)){ + lm_error_set(LM_ERR_PkgAlreadyInstalled); + return false; + } + + if(lm_package_path_is_empty(pkg)){ + lm_error_set(LM_ERR_PkgPathsEmpty); + return false; + } + if(!extract_archive(ctx->temp, pkg->paths.archive)) return false; // error set by function diff --git a/src/util.c b/src/util.c index 4aef5fd..7c71f13 100644 --- a/src/util.c +++ b/src/util.c @@ -140,6 +140,7 @@ bool extract_archive(char *dst, char *src) { char srcfull[PATH_MAX + 1]; if (NULL == realpath(src, srcfull)) { + pdebug(__func__, "failed to get realpath for %s: %s", src, strerror(errno)); lm_error_set(LM_ERR_ArcRealpathFail); goto end; }