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
This commit is contained in:
Juan RP 2009-10-16 15:31:57 +02:00
parent d771383442
commit e1f2a8b7bd
3 changed files with 43 additions and 12 deletions

View File

@ -220,10 +220,19 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
pkgd = xbps_find_pkg_installed_from_plist(pkg); pkgd = xbps_find_pkg_installed_from_plist(pkg);
if (update) { if (update) {
if (pkgd) { 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); printf("Package '%s' is up to date.\n", pkg);
prop_object_release(pkgd); prop_object_release(pkgd);
cleanup(rv); 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); prop_object_release(pkgd);
} else { } else {
@ -238,7 +247,8 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
} }
rv = xbps_prepare_pkg(pkg); rv = xbps_prepare_pkg(pkg);
if (rv != 0 && rv == EAGAIN) { 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); cleanup(rv);
} else if (rv != 0 && rv != ENOENT) { } else if (rv != 0 && rv != ENOENT) {
printf("Unexpected error: %s", strerror(rv)); 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, prop_dictionary_get_cstring_nocopy(trans->dict,
"origin", &trans->originpkgname); "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! * It's time to run the transaction!
*/ */
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages"); trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
if (trans->iter == NULL) { if (trans->iter == NULL) {
printf("error: allocating array mem! (%s)", printf("error: allocating array mem! (%s)\n",
strerror(errno)); strerror(errno));
goto out2; goto out2;
} }

View File

@ -130,6 +130,11 @@ main(int argc, char **argv)
goto out; 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) { if (strcasecmp(argv[0], "list") == 0) {
/* Lists packages currently registered in database. */ /* Lists packages currently registered in database. */
@ -267,6 +272,7 @@ main(int argc, char **argv)
} }
out: out:
xbps_release_repolist_data();
xbps_release_regpkgdb_dict(); xbps_release_regpkgdb_dict();
if (rv != 0) if (rv != 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@ -228,7 +228,10 @@ xbps_find_new_packages(void)
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); 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); prop_object_iterator_release(iter);
return rv; return rv;
} }
@ -246,6 +249,7 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
struct repository_data *rdata; struct repository_data *rdata;
const char *repoloc, *repover, *instver; const char *repoloc, *repover, *instver;
int rv = 0; int rv = 0;
bool newpkg_found = false;
assert(pkgname != NULL); assert(pkgname != NULL);
assert(instpkg != NULL); assert(instpkg != NULL);
@ -259,22 +263,24 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
"packages", pkgname); "packages", pkgname);
if (pkgrd != NULL) { if (pkgrd != NULL) {
/* /*
* Check if installed version is >= than the * Check if version in repository is greater than
* one available in current repository. * the version currently installed.
*/ */
prop_dictionary_get_cstring_nocopy(instpkg, prop_dictionary_get_cstring_nocopy(instpkg,
"version", &instver); "version", &instver);
prop_dictionary_get_cstring_nocopy(pkgrd, prop_dictionary_get_cstring_nocopy(pkgrd,
"version", &repover); "version", &repover);
if (xbps_cmpver(instver, repover) >= 0) if (xbps_cmpver(repover, instver) > 0) {
goto out; newpkg_found = true;
break;
break; }
} }
} }
if (pkgrd == NULL) if (!newpkg_found)
return 0; return EEXIST;
if (pkgrd == NULL)
return ENOENT;
/* /*
* Create master pkg dictionary. * Create master pkg dictionary.
*/ */