From 0ed055c4eb682b08297b44f22401674d713c948f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 17 Mar 2009 05:10:21 +0100 Subject: [PATCH] Don't continue installing a binpkg if newest version in repos is already installed. --HG-- extra : convert_revision : b73376d091fd95f4cfd92cbdba21f4bc93781504 --- bin/xbps-bin/main.c | 5 ++++- doc/TODO | 2 -- lib/install.c | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index 9f2b5755baa..dc4fd2817eb 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -214,7 +214,6 @@ main(int argc, char **argv) if (argc != 2) usage(); - /* Install into root directory by default. */ rv = xbps_install_binary_pkg(argv[1]); if (rv != 0) { if (rv == EAGAIN) { @@ -224,6 +223,10 @@ main(int argc, char **argv) dict = xbps_get_pkg_deps_dictionary(); if (dict) show_missing_deps(dict, argv[1]); + } else if (rv == EEXIST) { + printf("Package '%s' is already up to date.\n", + argv[1]); + exit(EXIT_SUCCESS); } exit(EXIT_FAILURE); diff --git a/doc/TODO b/doc/TODO index cc2c262eec8..67d06e4ace2 100644 --- a/doc/TODO +++ b/doc/TODO @@ -19,8 +19,6 @@ xbps-bin: * Show binpkg size and installed size for all packages that are going to be installed before installation happens. * Add support to update packages. [IN PROGRESS] - * While installing a package, check if version that is going to be - installed is already installed. [IN PROGRESS] * Add a flag to reinstall a package version that is already installed, overwritting files on disk and updating required_by if required. Perhaps change the automatic-install object to false, like pkg_install diff --git a/lib/install.c b/lib/install.c index 71260b26084..0885f7ceb94 100644 --- a/lib/install.c +++ b/lib/install.c @@ -90,8 +90,9 @@ static int install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done) { prop_dictionary_t repod, pkgrd; - const char *repoloc, *pkgname = arg; - char *plist; + size_t len = 0; + const char *repoloc, *instver, *pkgname = arg; + char *plist, *pkg; int rv = 0; plist = xbps_get_pkg_index_plist(prop_string_cstring_nocopy(obj)); @@ -116,6 +117,25 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done) return 0; } + /* + * Check if available version in repository is already installed, + * and return immediately in that case. + */ + prop_dictionary_get_cstring_nocopy(pkgrd, "version", &instver); + len = strlen(pkgname) + strlen(instver) + 2; + pkg = malloc(len); + if (pkg == NULL) { + rv = EINVAL; + goto out; + } + (void)snprintf(pkg, len, "%s-%s", pkgname, instver); + if (xbps_check_is_installed_pkg(pkg) == 0) { + free(pkg); + rv = EEXIST; + goto out; + } + free(pkg); + /* * Check SHA256 hash for binary package before anything else. */