Implemented blueprint 'install-pkg-by-pkgmatch' as specified in

https://blueprints.launchpad.net/xbps/+spec/install-pkg-by-pkgmatch

The implementation works as expected, it was easier that I thought.
Bump XBPS_RELVER because the API was changed slightly.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20100114011431-xv5q6bgahm6v9dbq
This commit is contained in:
Juan RP
2010-01-14 02:14:31 +01:00
parent 6c29fe7514
commit 023841b060
12 changed files with 120 additions and 41 deletions

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009 Juan Romero Pardines.
* Copyright (c) 2009-2010 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -319,10 +319,23 @@ xbps_autoupdate_pkgs(bool yes)
}
int
xbps_install_new_pkg(const char *pkgname)
xbps_install_new_pkg(const char *pkg)
{
prop_dictionary_t pkgd;
char *pkgname;
int rv = 0;
bool pkgmatch = false;
/*
* Check if 'pkg' string is a pkgmatch valid pattern or it
* is just a pkgname.
*/
if ((pkgname = xbps_get_pkgdep_name(pkg)))
pkgmatch = true;
else if ((pkgname = xbps_get_pkg_name(pkg)))
pkgmatch = true;
else
pkgname = __UNCONST(pkg);
/*
* Find a package in a repository and prepare for installation.
@@ -330,16 +343,21 @@ xbps_install_new_pkg(const char *pkgname)
if ((pkgd = xbps_find_pkg_installed_from_plist(pkgname))) {
printf("Package '%s' is already installed.\n", pkgname);
prop_object_release(pkgd);
if (pkgmatch)
free(pkgname);
return 0;
}
rv = xbps_repository_install_pkg(pkgname);
if (rv != 0 && rv == EAGAIN) {
rv = xbps_repository_install_pkg(pkg, pkgmatch);
if (rv == EAGAIN) {
printf("Unable to locate '%s' in "
"repository pool.\n", pkgname);
"repository pool.\n", pkg);
rv = 0;
} else if (rv != 0 && rv != ENOENT) {
printf("Unexpected error: %s", strerror(errno));
}
if (pkgmatch)
free(pkgname);
return rv;
}

View File

@@ -46,7 +46,7 @@ usage(void)
" autoremove\n"
" autoupdate\n"
" check\t\t[<pkgname>|<all>]\n"
" install\t\t<pkgname(s)>\n"
" install\t\t[<pkgname(s)>|<pkgpattern(s)>]\n"
" list\n"
" list-manual\n"
" purge\t\t[<pkgname>|<all>]\n"

View File

@@ -72,9 +72,11 @@ Please note that all targets are *case insensitive*.
'all' packages currently installed will be checked, otherwise only
*pkgname*.
*install 'pkgname(s)'*::
Install binary package "*pkgname*" by searching it in the
repository pool. The package(s) will be 'download' (if working with
*install 'pkgname(s)' | 'pkgpattern(s)'*::
Install binary package(s) from repository pool by specifying
"*pkgname(s)*" or "*package pattern(s)*".
The first repository matching the arguments will be used.
The package(s) will be 'download' (if working with
a remote repository), 'unpacked' and 'configured'. The 'unpack stage will
execute the *pre-install* action on its *INSTALL* script, and unpack its files.
The 'configure' stage will run the *post-install* action set on its
@@ -176,6 +178,20 @@ FILES
*/var/cache/xbps*:: xbps _cache_ directory for downloaded binary packages.
+
EXAMPLES
--------
*Install a package by specifying its name:*::
$ xbps-bin install foo
*Install a package by specifying a package pattern:*::
$ xbps-bin install "*foo>=3.0*"
*Install multiple packages by specifying names and package patterns:*::
$ xbps-bin install foo "*blah<=4.0*" baz-2.0 "*blob>4.[0-9]*"
BUGS
----
Probably, but I try to make this not happen. Use it under your own

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009 Juan Romero Pardines.
* Copyright (c) 2009-2010 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -129,7 +129,7 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
* than current registered package, update the index; otherwise
* pass to the next one.
*/
curpkgd = xbps_find_pkg_in_dict(idxdict, "packages", pkgname);
curpkgd = xbps_find_pkg_in_dict_by_name(idxdict, "packages", pkgname);
if (curpkgd == NULL) {
if (errno && errno != ENOENT) {
prop_object_release(newpkgd);

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2009 Juan Romero Pardines.
* Copyright (c) 2008-2010 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -219,7 +219,7 @@ show_pkg_info_from_repolist(const char *pkgname)
SIMPLEQ_FOREACH(rp, &repopool_queue, chain) {
char *url = NULL;
repo_pkgd = xbps_find_pkg_in_dict(rp->rp_repod,
repo_pkgd = xbps_find_pkg_in_dict_by_name(rp->rp_repod,
"packages", pkgname);
if (repo_pkgd == NULL) {
if (errno && errno != ENOENT) {
@@ -260,7 +260,8 @@ show_pkg_deps_from_repolist(const char *pkgname)
int rv = 0;
SIMPLEQ_FOREACH(rd, &repopool_queue, chain) {
pkgd = xbps_find_pkg_in_dict(rd->rp_repod, "packages", pkgname);
pkgd = xbps_find_pkg_in_dict_by_name(rd->rp_repod,
"packages", pkgname);
if (pkgd == NULL) {
if (errno != ENOENT) {
rv = errno;