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:
parent
6c29fe7514
commit
023841b060
@ -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,17 +343,22 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
@ -40,7 +40,7 @@
|
||||
#include <archive_entry.h>
|
||||
|
||||
/* Current release version */
|
||||
#define XBPS_RELVER "20091222"
|
||||
#define XBPS_RELVER "20100114"
|
||||
|
||||
/* Default root PATH for xbps to store metadata info. */
|
||||
#define XBPS_META_PATH "/var/db/xbps"
|
||||
@ -151,8 +151,12 @@ int SYMEXPORT xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t,
|
||||
int (*fn)(prop_object_t, void *, bool *),
|
||||
void *);
|
||||
|
||||
prop_dictionary_t SYMEXPORT xbps_find_pkg_in_dict(prop_dictionary_t,
|
||||
const char *, const char *);
|
||||
prop_dictionary_t SYMEXPORT
|
||||
xbps_find_pkg_in_dict_by_name(prop_dictionary_t,
|
||||
const char *, const char *);
|
||||
prop_dictionary_t SYMEXPORT
|
||||
xbps_find_pkg_in_dict_by_pkgmatch(prop_dictionary_t,
|
||||
const char *, const char *);
|
||||
prop_dictionary_t SYMEXPORT xbps_find_pkg_from_plist(const char *,
|
||||
const char *);
|
||||
prop_dictionary_t SYMEXPORT
|
||||
@ -200,7 +204,7 @@ int SYMEXPORT xbps_repository_find_pkg_deps(prop_dictionary_t,
|
||||
prop_dictionary_t);
|
||||
|
||||
/* From lib/repository_findpkg.c */
|
||||
int SYMEXPORT xbps_repository_install_pkg(const char *);
|
||||
int SYMEXPORT xbps_repository_install_pkg(const char *, bool);
|
||||
int SYMEXPORT xbps_repository_update_pkg(const char *, prop_dictionary_t);
|
||||
int SYMEXPORT xbps_repository_update_allpkgs(void);
|
||||
prop_dictionary_t SYMEXPORT xbps_repository_get_transaction_dict(void);
|
||||
|
42
lib/plist.c
42
lib/plist.c
@ -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
|
||||
@ -134,7 +134,7 @@ xbps_find_pkg_from_plist(const char *plist, const char *pkgname)
|
||||
if (dict == NULL)
|
||||
return NULL;
|
||||
|
||||
obj = xbps_find_pkg_in_dict(dict, "packages", pkgname);
|
||||
obj = xbps_find_pkg_in_dict_by_name(dict, "packages", pkgname);
|
||||
if (obj == NULL) {
|
||||
prop_object_release(dict);
|
||||
return NULL;
|
||||
@ -155,7 +155,7 @@ xbps_find_pkg_installed_from_plist(const char *pkgname)
|
||||
if ((d = xbps_regpkgs_dictionary_init()) == NULL)
|
||||
return NULL;
|
||||
|
||||
pkgd = xbps_find_pkg_in_dict(d, "packages", pkgname);
|
||||
pkgd = xbps_find_pkg_in_dict_by_name(d, "packages", pkgname);
|
||||
if (pkgd == NULL)
|
||||
goto fail;
|
||||
|
||||
@ -179,8 +179,8 @@ fail:
|
||||
}
|
||||
|
||||
prop_dictionary_t SYMEXPORT
|
||||
xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key,
|
||||
const char *pkgname)
|
||||
xbps_find_pkg_in_dict_by_name(prop_dictionary_t dict, const char *key,
|
||||
const char *pkgname)
|
||||
{
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj = NULL;
|
||||
@ -190,8 +190,7 @@ xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key,
|
||||
assert(pkgname != NULL);
|
||||
assert(key != NULL);
|
||||
|
||||
iter = xbps_get_array_iter_from_dict(dict, key);
|
||||
if (iter == NULL)
|
||||
if ((iter = xbps_get_array_iter_from_dict(dict, key)) == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
@ -208,6 +207,35 @@ xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key,
|
||||
return obj;
|
||||
}
|
||||
|
||||
prop_dictionary_t SYMEXPORT
|
||||
xbps_find_pkg_in_dict_by_pkgmatch(prop_dictionary_t dict, const char *key,
|
||||
const char *pkgmatch)
|
||||
{
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj = NULL;
|
||||
const char *pkgver;
|
||||
|
||||
assert(dict != NULL);
|
||||
assert(key != NULL);
|
||||
assert(pkgmatch != NULL);
|
||||
|
||||
if ((iter = xbps_get_array_iter_from_dict(dict, key)) == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &pkgver))
|
||||
break;
|
||||
if (xbps_pkgdep_match(pkgver, __UNCONST(pkgmatch)))
|
||||
break;
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
if (obj == NULL)
|
||||
errno = ENOENT;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
bool SYMEXPORT
|
||||
xbps_find_string_in_array(prop_array_t array, const char *val)
|
||||
{
|
||||
|
@ -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
|
||||
@ -63,7 +63,8 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic)
|
||||
}
|
||||
|
||||
if ((dict = prop_dictionary_internalize_from_file(plist)) != NULL) {
|
||||
pkgd = xbps_find_pkg_in_dict(dict, "packages", pkgname);
|
||||
pkgd = xbps_find_pkg_in_dict_by_name(dict,
|
||||
"packages", pkgname);
|
||||
if (pkgd == NULL) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
|
@ -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
|
||||
@ -363,7 +363,8 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
||||
* array of unsorted deps, and check if current required
|
||||
* dependency pattern is matched.
|
||||
*/
|
||||
curpkgd = xbps_find_pkg_in_dict(master, "unsorted_deps", pkgname);
|
||||
curpkgd = xbps_find_pkg_in_dict_by_name(master,
|
||||
"unsorted_deps", pkgname);
|
||||
if (curpkgd == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
free(pkgname);
|
||||
@ -390,7 +391,8 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
|
||||
* If required package is not in repo, add it into the
|
||||
* missing deps array and pass to the next one.
|
||||
*/
|
||||
curpkgd = xbps_find_pkg_in_dict(repo, "packages", pkgname);
|
||||
curpkgd = xbps_find_pkg_in_dict_by_name(repo,
|
||||
"packages", pkgname);
|
||||
if (curpkgd == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
free(pkgname);
|
||||
|
@ -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
|
||||
@ -178,7 +178,7 @@ xbps_repository_update_pkg(const char *pkgname, prop_dictionary_t instpkg)
|
||||
* Get the package dictionary from current repository.
|
||||
* If it's not there, pass to the next repository.
|
||||
*/
|
||||
pkgrd = xbps_find_pkg_in_dict(rpool->rp_repod,
|
||||
pkgrd = xbps_find_pkg_in_dict_by_name(rpool->rp_repod,
|
||||
"packages", pkgname);
|
||||
if (pkgrd == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
@ -298,14 +298,15 @@ set_pkg_state(prop_dictionary_t pkgd, const char *pkgname)
|
||||
}
|
||||
|
||||
int SYMEXPORT
|
||||
xbps_repository_install_pkg(const char *pkgname)
|
||||
xbps_repository_install_pkg(const char *pkg, bool by_pkgmatch)
|
||||
{
|
||||
prop_dictionary_t origin_pkgrd = NULL, pkgrd = NULL;
|
||||
prop_array_t unsorted;
|
||||
struct repository_pool *rpool;
|
||||
const char *pkgname;
|
||||
int rv = 0;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
assert(pkg != NULL);
|
||||
|
||||
if ((rv = xbps_repository_pool_init()) != 0)
|
||||
return rv;
|
||||
@ -315,8 +316,13 @@ xbps_repository_install_pkg(const char *pkgname)
|
||||
* Get the package dictionary from current repository.
|
||||
* If it's not there, pass to the next repository.
|
||||
*/
|
||||
pkgrd = xbps_find_pkg_in_dict(rpool->rp_repod,
|
||||
"packages", pkgname);
|
||||
if (by_pkgmatch)
|
||||
pkgrd = xbps_find_pkg_in_dict_by_pkgmatch(
|
||||
rpool->rp_repod, "packages", pkg);
|
||||
else
|
||||
pkgrd = xbps_find_pkg_in_dict_by_name(
|
||||
rpool->rp_repod, "packages", pkg);
|
||||
|
||||
if (pkgrd == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
rv = errno;
|
||||
@ -345,6 +351,8 @@ xbps_repository_install_pkg(const char *pkgname)
|
||||
}
|
||||
origin_pkgrd = prop_dictionary_copy(pkgrd);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname);
|
||||
|
||||
/*
|
||||
* Prepare required package dependencies.
|
||||
*/
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2010 Juan Romero Pardines.
|
||||
* Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg (at) NetBSD.org>
|
||||
* Copyright (c) 2009 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -239,7 +239,7 @@ xbps_repository_get_pkg_plist_dict(const char *pkgname, const char *plistf)
|
||||
* libfetch!
|
||||
*/
|
||||
SIMPLEQ_FOREACH(rpool, &repopool_queue, chain) {
|
||||
pkgd = xbps_find_pkg_in_dict(rpool->rp_repod,
|
||||
pkgd = xbps_find_pkg_in_dict_by_name(rpool->rp_repod,
|
||||
"packages", pkgname);
|
||||
if (pkgd == NULL) {
|
||||
if (errno != ENOENT)
|
||||
|
@ -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
|
||||
@ -189,7 +189,8 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
|
||||
}
|
||||
|
||||
} else {
|
||||
pkgd = xbps_find_pkg_in_dict(dict, "packages", pkgname);
|
||||
pkgd = xbps_find_pkg_in_dict_by_name(dict,
|
||||
"packages", pkgname);
|
||||
if (pkgd == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
rv = errno;
|
||||
|
Loading…
Reference in New Issue
Block a user