From 27f354a7874b965bf223832bdf9749504cd1a590 Mon Sep 17 00:00:00 2001 From: morganamilo Date: Wed, 6 Nov 2019 01:42:11 +0000 Subject: pacman+libalpm: handle search errors Previously, pacman treated no matches and an error during search the same. To fix this, alpm_db_search now returns its status as an int and instead takes the to be returned list as a param. Allowing front ends to easily differentiate between errors and no matches. Signed-off-by: morganamilo Signed-off-by: Allan McRae --- src/pacman/package.c | 7 +++++-- src/pacman/query.c | 10 +++++++++- src/pacman/sync.c | 10 +++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/pacman/package.c b/src/pacman/package.c index 35cfcd94..ec6e78fc 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -518,12 +518,13 @@ void print_groups(alpm_pkg_t *pkg) * @param db the database we're searching * @param targets the targets we're searching for * @param show_status show if the package is also in the local db + * @return -1 on error, 0 if there were matches, 1 if there were not */ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) { int freelist = 0; alpm_db_t *db_local; - alpm_list_t *i, *searchlist; + alpm_list_t *i, *searchlist = NULL; unsigned short cols; const colstr_t *colstr = &config->colstr; @@ -533,7 +534,9 @@ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) /* if we have a targets list, search for packages matching it */ if(targets) { - searchlist = alpm_db_search(db, targets); + if(alpm_db_search(db, targets, &searchlist) != 0) { + return -1; + } freelist = 1; } else { searchlist = alpm_db_get_pkgcache(db); diff --git a/src/pacman/query.c b/src/pacman/query.c index 2b9ee7a6..bdcfc3c1 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -233,7 +233,15 @@ targcleanup: static int query_search(alpm_list_t *targets) { alpm_db_t *db_local = alpm_get_localdb(config->handle); - return dump_pkg_search(db_local, targets, 0); + int ret = dump_pkg_search(db_local, targets, 0); + if(ret == -1) { + alpm_errno_t err = alpm_errno(config->handle); + pm_printf(ALPM_LOG_ERROR, "search failed: %s\n", alpm_strerror(err)); + return 1; + } + + return ret; + } static unsigned short pkg_get_locality(alpm_pkg_t *pkg) diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 9033cee7..4bdeff7b 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -311,7 +311,15 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) for(i = syncs; i; i = alpm_list_next(i)) { alpm_db_t *db = i->data; - found += !dump_pkg_search(db, targets, 1); + int ret = dump_pkg_search(db, targets, 1); + + if(ret == -1) { + alpm_errno_t err = alpm_errno(config->handle); + pm_printf(ALPM_LOG_ERROR, "search failed: %s\n", alpm_strerror(err)); + return 1; + } + + found += !ret; } return (found == 0); -- cgit v1.2.3-54-g00ecf