diff --git a/bin/xbps-bin/install.c b/bin/xbps-bin/install.c index a250075fc61..01598ccbaa9 100644 --- a/bin/xbps-bin/install.c +++ b/bin/xbps-bin/install.c @@ -435,25 +435,18 @@ void xbps_autoupdate_pkgs(bool force) { struct transaction *trans; - prop_dictionary_t dict; - prop_object_t obj; - const char *pkgname; int rv = 0; /* - * Prepare dictionary with all registered packages. + * Find new package versions. */ - dict = xbps_prepare_regpkgdb_dict(); - if (dict == NULL) { - printf("No packages currently installed (%s).\n", - strerror(errno)); - cleanup(rv); - } - /* - * Prepare dictionary with all registered repositories. - */ - if ((rv = xbps_prepare_repolist_data()) != 0) + if ((rv = xbps_find_new_packages()) != 0) { + if (rv == ENOENT) { + printf("No packages currently registered.\n"); + cleanup(0); + } goto out; + } /* * Prepare transaction data. @@ -462,26 +455,6 @@ xbps_autoupdate_pkgs(bool force) if (trans == NULL) goto out; - trans->iter = xbps_get_array_iter_from_dict(dict, "packages"); - if (trans->iter == NULL) { - rv = EINVAL; - goto out1; - } - - /* - * Find out if there is a newer version for all currently - * installed packages. - */ - while ((obj = prop_object_iterator_next(trans->iter)) != NULL) { - prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); - rv = xbps_find_new_pkg(pkgname, obj); - if (rv != 0) { - prop_object_iterator_release(trans->iter); - goto out1; - } - } - prop_object_iterator_release(trans->iter); - /* * Get package transaction dictionary. */ diff --git a/include/xbps_api.h b/include/xbps_api.h index b3c9eba61f2..35c5ceafc17 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -98,6 +98,7 @@ SIMPLEQ_HEAD(, repository_data) repodata_queue; int xbps_prepare_pkg(const char *); int xbps_find_new_pkg(const char *, prop_dictionary_t); +int xbps_find_new_packages(void); int xbps_prepare_repolist_data(void); void xbps_release_repolist_data(void); prop_dictionary_t xbps_get_pkg_props(void); diff --git a/lib/findpkg.c b/lib/findpkg.c index 548c72b5627..f6c04a55dda 100644 --- a/lib/findpkg.c +++ b/lib/findpkg.c @@ -197,6 +197,48 @@ xbps_release_repolist_data(void) } } +int +xbps_find_new_packages(void) +{ + prop_dictionary_t dict; + prop_object_t obj; + prop_object_iterator_t iter; + const char *pkgname; + int rv = 0; + + /* + * Prepare dictionary with all registered packages. + */ + dict = xbps_prepare_regpkgdb_dict(); + if (dict == NULL) + return ENOENT; + + /* + * Prepare dictionary with all registered repositories. + */ + if ((rv = xbps_prepare_repolist_data()) != 0) + return rv; + + iter = xbps_get_array_iter_from_dict(dict, "packages"); + if (iter == NULL) + return EINVAL; + + /* + * Find out if there is a newer version for all currently + * installed packages. + */ + while ((obj = prop_object_iterator_next(iter)) != NULL) { + prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); + if ((rv = xbps_find_new_pkg(pkgname, obj)) != 0) { + prop_object_iterator_release(iter); + return rv; + } + } + prop_object_iterator_reset(iter); + + return rv; +} + int xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg) {