From e1f2a8b7bdab6c58e4ca3bc609401f8e85c747bb Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 16 Oct 2009 15:31:57 +0200 Subject: [PATCH] xbps-bin: multiple fixes to update packages. * Fix 'autoupdate' target to look for new packages in ALL repos, not just the first one that has the package. * Fix 'update' target to work correctly. --HG-- extra : convert_revision : xtraeme%40gmail.com-20091016133157-asvkv5jb6i9q2ibe --- bin/xbps-bin/install.c | 25 ++++++++++++++++++++++--- bin/xbps-bin/main.c | 6 ++++++ lib/findpkg.c | 24 +++++++++++++++--------- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/bin/xbps-bin/install.c b/bin/xbps-bin/install.c index 6442b546..75653389 100644 --- a/bin/xbps-bin/install.c +++ b/bin/xbps-bin/install.c @@ -220,10 +220,19 @@ xbps_install_pkg(const char *pkg, bool force, bool update) pkgd = xbps_find_pkg_installed_from_plist(pkg); if (update) { if (pkgd) { - if ((rv = xbps_find_new_pkg(pkg, pkgd)) == 0) { + rv = xbps_find_new_pkg(pkg, pkgd); + if (rv == EEXIST) { printf("Package '%s' is up to date.\n", pkg); prop_object_release(pkgd); cleanup(rv); + } else if (rv == ENOENT) { + printf("Package '%s' not found in " + "repository pool.\n", pkg); + prop_object_release(pkgd); + cleanup(rv); + } else if (rv != 0) { + prop_object_release(pkgd); + cleanup(rv); } prop_object_release(pkgd); } else { @@ -238,7 +247,8 @@ xbps_install_pkg(const char *pkg, bool force, bool update) } rv = xbps_prepare_pkg(pkg); if (rv != 0 && rv == EAGAIN) { - printf("Unable to locate '%s' in repository pool.\n", pkg); + printf("Unable to locate '%s' in repository pool.\n", + pkg); cleanup(rv); } else if (rv != 0 && rv != ENOENT) { printf("Unexpected error: %s", strerror(rv)); @@ -268,12 +278,21 @@ xbps_install_pkg(const char *pkg, bool force, bool update) prop_dictionary_get_cstring_nocopy(trans->dict, "origin", &trans->originpkgname); + /* + * Sort the package transaction dictionary. + */ + if ((rv = xbps_sort_pkg_deps(trans->dict)) != 0) { + printf("Error while sorting packages: %s\n", + strerror(rv)); + goto out2; + } + /* * It's time to run the transaction! */ trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages"); if (trans->iter == NULL) { - printf("error: allocating array mem! (%s)", + printf("error: allocating array mem! (%s)\n", strerror(errno)); goto out2; } diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 2722b0a8..7245e9ab 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -130,6 +130,11 @@ main(int argc, char **argv) goto out; } } + if ((rv = xbps_prepare_repolist_data()) != 0) { + printf("Couldn't initialized repository pool data (%s)\n", + strerror(rv)); + goto out; + } if (strcasecmp(argv[0], "list") == 0) { /* Lists packages currently registered in database. */ @@ -267,6 +272,7 @@ main(int argc, char **argv) } out: + xbps_release_repolist_data(); xbps_release_regpkgdb_dict(); if (rv != 0) exit(EXIT_FAILURE); diff --git a/lib/findpkg.c b/lib/findpkg.c index f1f82404..65f6d06a 100644 --- a/lib/findpkg.c +++ b/lib/findpkg.c @@ -228,7 +228,10 @@ xbps_find_new_packages(void) */ 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) { + rv = xbps_find_new_pkg(pkgname, obj); + if (rv == ENOENT || rv == EEXIST) + continue; + else if (rv != 0) { prop_object_iterator_release(iter); return rv; } @@ -246,6 +249,7 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg) struct repository_data *rdata; const char *repoloc, *repover, *instver; int rv = 0; + bool newpkg_found = false; assert(pkgname != NULL); assert(instpkg != NULL); @@ -259,22 +263,24 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg) "packages", pkgname); if (pkgrd != NULL) { /* - * Check if installed version is >= than the - * one available in current repository. + * Check if version in repository is greater than + * the version currently installed. */ prop_dictionary_get_cstring_nocopy(instpkg, "version", &instver); prop_dictionary_get_cstring_nocopy(pkgrd, "version", &repover); - if (xbps_cmpver(instver, repover) >= 0) - goto out; - - break; + if (xbps_cmpver(repover, instver) > 0) { + newpkg_found = true; + break; + } } } - if (pkgrd == NULL) - return 0; + if (!newpkg_found) + return EEXIST; + if (pkgrd == NULL) + return ENOENT; /* * Create master pkg dictionary. */