xbps-bin: added support to install exact pkg version, i.e 'foo-1.0'.

This commit is contained in:
Juan RP 2012-06-02 17:35:21 +02:00
parent 40864bcdce
commit bd3a8982cc
3 changed files with 48 additions and 22 deletions

7
NEWS
View File

@ -1,5 +1,12 @@
xbps-0.16 (???): xbps-0.16 (???):
* xbps-bin(8): the 'install' target now can (re)install an exact package
version as specified on its arguments, i.e:
$ xbps-bin install foo-1.0
If that version is not available no other version will be installed.
* xbps-repo(8): 'genindex' target is now able to remove binary packages * xbps-repo(8): 'genindex' target is now able to remove binary packages
when a greater version exists on the index. when a greater version exists on the index.

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20120601-2" #define XBPS_API_VERSION "20120602"
#define XBPS_VERSION "0.16" #define XBPS_VERSION "0.16"
/** /**
@ -1360,8 +1360,8 @@ int xbps_remove_pkg_files(prop_dictionary_t dict,
* package version in repository pool will be queued, otherwise the first * package version in repository pool will be queued, otherwise the first
* repository matching the package pattern wins. * repository matching the package pattern wins.
* *
* @param pkg Package name or package pattern to match, i.e * @param pkg Package name, package/version or package pattern to match, i.e
* `foo>=0' or 'foo<1'. * `foo', `foo-1.0' or `foo>=1.2'.
* @param reinstall If true, package will be queued (if \a str matches) * @param reinstall If true, package will be queued (if \a str matches)
* even if package is already installed. * even if package is already installed.
* *

View File

@ -57,12 +57,13 @@ enum {
}; };
static int static int
transaction_find_pkg(const char *pkg, bool bypattern, bool bestpkg, int action) transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
int action)
{ {
prop_dictionary_t pkg_pkgdb, pkg_repod; prop_dictionary_t pkg_pkgdb, pkg_repod;
prop_array_t unsorted; prop_array_t unsorted;
struct xbps_handle *xhp = xbps_handle_get(); struct xbps_handle *xhp = xbps_handle_get();
const char *pkgname, *pkgver, *repoloc, *repover, *instver, *reason; const char *pkgname, *repoloc, *repover, *instver, *reason;
int rv = 0; int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
@ -83,13 +84,21 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool bestpkg, int action)
* Find out if the pkg has been found in repository pool. * Find out if the pkg has been found in repository pool.
*/ */
if (action == TRANS_INSTALL) { if (action == TRANS_INSTALL) {
if (exact) {
if ((pkg_repod = xbps_rpool_find_pkg_exact(pkg)) == NULL) {
/* not found */
rv = errno;
goto out;
}
} else {
if (((pkg_repod = xbps_rpool_find_virtualpkg_conf(pkg, bypattern)) == NULL) && if (((pkg_repod = xbps_rpool_find_virtualpkg_conf(pkg, bypattern)) == NULL) &&
((pkg_repod = xbps_rpool_find_pkg(pkg, bypattern, bestpkg)) == NULL) && ((pkg_repod = xbps_rpool_find_pkg(pkg, bypattern, best)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg(pkg, bypattern)) == NULL)) { ((pkg_repod = xbps_rpool_find_virtualpkg(pkg, bypattern)) == NULL)) {
/* not found */ /* not found */
rv = errno; rv = errno;
goto out; goto out;
} }
}
} else { } else {
if ((pkg_repod = xbps_rpool_find_pkg(pkg, false, true)) == NULL) { if ((pkg_repod = xbps_rpool_find_pkg(pkg, false, true)) == NULL) {
/* not found */ /* not found */
@ -101,7 +110,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool bestpkg, int action)
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &repover); prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &repover);
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc); prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
if (bestpkg && (action == TRANS_UPDATE)) { if (best && (action == TRANS_UPDATE)) {
/* /*
* Compare installed version vs best pkg available in repos. * Compare installed version vs best pkg available in repos.
*/ */
@ -207,7 +216,8 @@ xbps_transaction_update_packages(void)
continue; continue;
} }
} }
rv = transaction_find_pkg(pkgname, false, true, TRANS_UPDATE); rv = transaction_find_pkg(pkgname, false, true,
false, TRANS_UPDATE);
if (rv == 0) if (rv == 0)
newpkg_found = true; newpkg_found = true;
else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) { else if (rv == ENOENT || rv == EEXIST || rv == ENODEV) {
@ -225,7 +235,7 @@ xbps_transaction_update_packages(void)
int int
xbps_transaction_update_pkg(const char *pkgname) xbps_transaction_update_pkg(const char *pkgname)
{ {
return transaction_find_pkg(pkgname, false, true, TRANS_UPDATE); return transaction_find_pkg(pkgname, false, true, false, TRANS_UPDATE);
} }
int int
@ -233,17 +243,27 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
{ {
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
pkg_state_t state; pkg_state_t state;
bool bypattern, bestpkg; char *pkgname;
bool bypattern, best, exact;
if (xbps_pkgpattern_version(pkg)) { if (xbps_pkgpattern_version(pkg)) {
bypattern = true; bypattern = true;
bestpkg = false; best = false;
} else { exact = false;
} else if (xbps_pkg_version(pkg)) {
exact = true;
bypattern = false; bypattern = false;
bestpkg = true; best = false;
}
pkgd = xbps_pkgdb_get_pkgd(pkg, bypattern); pkgd = xbps_pkgdb_get_pkgd(pkg, bypattern);
pkgname = xbps_pkg_name(pkg);
assert(pkgname != NULL);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
free(pkgname);
} else {
exact = false;
bypattern = false;
best = true;
}
if (pkgd != NULL) { if (pkgd != NULL) {
if (xbps_pkg_state_dictionary(pkgd, &state) != 0) { if (xbps_pkg_state_dictionary(pkgd, &state) != 0) {
prop_object_release(pkgd); prop_object_release(pkgd);
@ -255,8 +275,7 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
return EEXIST; return EEXIST;
} }
} }
return transaction_find_pkg(pkg, bypattern, best, exact, TRANS_INSTALL);
return transaction_find_pkg(pkg, bypattern, bestpkg, TRANS_INSTALL);
} }
int int