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) 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)
{

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
@@ -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;

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
@@ -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);

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
@@ -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.
*/

View File

@@ -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)

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
@@ -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;