regpkgdb rototill: renamed to pkgdb, improve the public API.

This commit is contained in:
Juan RP
2012-01-20 11:10:52 +01:00
parent 9a088937b5
commit 6940505de9
31 changed files with 561 additions and 447 deletions

View File

@@ -196,7 +196,7 @@ xbps_end(void)
if (!xbps_initialized)
return;
xbps_regpkgdb_dictionary_release(xhp);
xbps_pkgdb_release(xhp);
xbps_repository_pool_release(xhp);
xbps_fetch_unset_cache_connection();

View File

@@ -65,9 +65,9 @@ xbps_configure_packages(bool flush)
struct xbps_handle *xhp = xbps_handle_get();
int rv;
rv = xbps_regpkgdb_foreach_pkg_cb(configure_pkgs_cb, NULL);
rv = xbps_pkgdb_foreach_pkg_cb(configure_pkgs_cb, NULL);
if (rv == 0 && flush)
rv = xbps_regpkgdb_update(xhp, true);
rv = xbps_pkgdb_update(xhp, true);
return rv;
}
@@ -109,7 +109,7 @@ xbps_configure_pkg(const char *pkgname,
} else if (state != XBPS_PKG_STATE_UNPACKED)
return EINVAL;
pkgd = xbps_regpkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
prop_dictionary_get_cstring_nocopy(pkgd, "version", &lver);
prop_object_release(pkgd);
} else {
@@ -169,7 +169,7 @@ xbps_configure_pkg(const char *pkgname,
}
free(pkgver);
if (flush)
rv = xbps_regpkgdb_update(xhp, true);
rv = xbps_pkgdb_update(xhp, true);
return rv;
}

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2011 Juan Romero Pardines.
* Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -176,12 +176,11 @@ xbps_find_pkg_orphans(prop_array_t orphans_user)
if ((od.array = prop_array_create()) == NULL)
return NULL;
/*
* Find out all orphans by looking at the
* regpkgdb dictionary and iterate in reverse order
* in which packages were installed.
* Find out all orphans by looking at pkgdb and iterating in reverse
* order in which packages were installed.
*/
od.orphans_user = orphans_user;
rv = xbps_regpkgdb_foreach_reverse_pkg_cb(find_orphan_pkg, &od);
rv = xbps_pkgdb_foreach_reverse_pkg_cb(find_orphan_pkg, &od);
if (rv != 0) {
errno = rv;
prop_object_release(od.array);

View File

@@ -43,7 +43,6 @@ int
xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
{
struct xbps_handle *xhp;
prop_array_t array;
prop_dictionary_t pkgd = NULL;
prop_array_t provides, reqby;
const char *pkgname, *version, *desc, *pkgver;
@@ -69,7 +68,7 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
assert(desc != NULL);
assert(pkgver != NULL);
pkgd = xbps_regpkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
if (pkgd == NULL) {
rv = ENOENT;
goto out;
@@ -127,16 +126,11 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
goto out;
}
}
array = prop_dictionary_get(xhp->regpkgdb, "packages");
rv = xbps_array_replace_dict_by_name(array, pkgd, pkgname);
if (rv != 0) {
if (!xbps_pkgdb_replace_pkgd(pkgd, pkgname, false, flush)) {
xbps_dbg_printf("%s: failed to replace pkgd dict for %s\n",
__func__, pkgname);
goto out;
}
if (flush)
rv = xbps_regpkgdb_update(xhp, true);
out:
if (pkgd != NULL)
prop_object_release(pkgd);
@@ -154,23 +148,16 @@ out:
int
xbps_unregister_pkg(const char *pkgname, const char *version, bool flush)
{
struct xbps_handle *xhp;
assert(pkgname != NULL);
xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL);
if (!xbps_regpkgdb_remove_pkgd(pkgname)) {
if (!xbps_pkgdb_remove_pkgd(pkgname, false, flush)) {
xbps_set_cb_state(XBPS_STATE_UNREGISTER_FAIL,
errno, pkgname, version,
"%s: failed to unregister package: %s",
pkgname, strerror(errno));
return errno;
}
if (flush) {
xhp = xbps_handle_get();
return xbps_regpkgdb_update(xhp, true);
}
return 0;
}

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2011 Juan Romero Pardines.
* Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -413,7 +413,7 @@ purge:
goto out;
}
/*
* Unregister package from regpkgdb.
* Unregister package from pkgdb.
*/
if ((rv = xbps_unregister_pkg(pkgname, version, false)) != 0)
goto out;

View File

@@ -103,14 +103,14 @@ int HIDDEN
xbps_requiredby_pkg_remove(const char *pkgname)
{
assert(pkgname != NULL);
return xbps_regpkgdb_foreach_pkg_cb(remove_pkg_from_reqby, __UNCONST(pkgname));
return xbps_pkgdb_foreach_pkg_cb(remove_pkg_from_reqby, __UNCONST(pkgname));
}
int HIDDEN
xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
{
prop_array_t pkg_rdeps;
prop_object_t obj, pkgd_regpkgdb;
prop_object_t obj, pkgd_pkgdb;
prop_object_iterator_t iter;
const char *pkgver, *str;
int rv = 0;
@@ -134,20 +134,20 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
}
xbps_dbg_printf("%s: adding reqby entry for %s\n", __func__, str);
pkgd_regpkgdb = xbps_find_virtualpkg_conf_in_dict_by_pattern(
xhp->regpkgdb, "packages", str);
if (pkgd_regpkgdb == NULL) {
pkgd_regpkgdb =
xbps_find_virtualpkg_in_dict_by_pattern(
xhp->regpkgdb, "packages", str);
if (pkgd_regpkgdb == NULL) {
pkgd_pkgdb = xbps_find_virtualpkg_conf_in_array_by_pattern(
xhp->pkgdb, str);
if (pkgd_pkgdb == NULL) {
pkgd_pkgdb =
xbps_find_virtualpkg_in_array_by_pattern(
xhp->pkgdb, str);
if (pkgd_pkgdb == NULL) {
rv = ENOENT;
xbps_dbg_printf("%s: couldnt find `%s' "
"entry in regpkgdb\n", __func__, str);
"entry in pkgdb\n", __func__, str);
break;
}
}
rv = add_pkg_into_reqby(pkgd_regpkgdb, pkgver);
rv = add_pkg_into_reqby(pkgd_pkgdb, pkgver);
if (rv != 0)
break;
}

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2011 Juan Romero Pardines.
* Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -100,7 +100,7 @@ xbps_pkg_state_installed(const char *pkgname, pkg_state_t *state)
assert(pkgname != NULL);
assert(state != NULL);
pkgd = xbps_regpkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
if (pkgd == NULL)
return ENOENT;
@@ -161,49 +161,43 @@ xbps_set_pkg_state_installed(const char *pkgname,
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd;
prop_array_t array;
bool newpkg = false;
int rv;
assert(pkgname != NULL);
xhp = xbps_handle_get();
if (xhp->regpkgdb == NULL) {
xhp->regpkgdb = prop_dictionary_create();
if (xhp->regpkgdb == NULL)
return ENOMEM;
array = prop_array_create();
if (array == NULL)
if (xhp->pkgdb == NULL) {
xhp->pkgdb = prop_array_create();
if (xhp->pkgdb == NULL)
return ENOMEM;
pkgd = prop_dictionary_create();
if (pkgd == NULL) {
prop_object_release(array);
prop_object_release(xhp->pkgdb);
xhp->pkgdb = NULL;
return ENOMEM;
}
if ((rv = set_pkg_objs(pkgd, pkgname, version, pkgver)) != 0) {
prop_object_release(array);
prop_object_release(xhp->pkgdb);
prop_object_release(pkgd);
xhp->pkgdb = NULL;
return rv;
}
if ((rv = set_new_state(pkgd, state)) != 0) {
prop_object_release(array);
prop_object_release(xhp->pkgdb);
prop_object_release(pkgd);
xhp->pkgdb = NULL;
return rv;
}
if (!xbps_add_obj_to_array(array, pkgd)) {
prop_object_release(array);
if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) {
prop_object_release(xhp->pkgdb);
prop_object_release(pkgd);
xhp->pkgdb = NULL;
return EINVAL;
}
if (!xbps_add_obj_to_dict(xhp->regpkgdb, array, "packages")) {
prop_object_release(array);
return EINVAL;
}
} else {
pkgd = xbps_regpkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
if (pkgd == NULL) {
newpkg = true;
pkgd = prop_dictionary_create();
@@ -218,21 +212,18 @@ xbps_set_pkg_state_installed(const char *pkgname,
prop_object_release(pkgd);
return rv;
}
array = prop_dictionary_get(xhp->regpkgdb, "packages");
if (newpkg) {
if (!xbps_add_obj_to_array(array, pkgd)) {
if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) {
prop_object_release(pkgd);
return EINVAL;
}
} else {
if ((rv = xbps_array_replace_dict_by_name(array,
if ((rv = xbps_array_replace_dict_by_name(xhp->pkgdb,
pkgd, pkgname)) != 0)
return rv;
prop_object_release(pkgd);
}
if (!prop_dictionary_set(xhp->regpkgdb, "packages", array))
return EINVAL;
}
return rv;

View File

@@ -136,10 +136,12 @@ extract_metafile(struct archive *ar,
rv, pkgname, version,
"%s: [unpack] failed to extract metafile `%s': %s",
pkgver, file, strerror(rv));
free(dirc);
free(pkgname);
return rv;
}
free(pkgname);
free(dirc);
return 0;
}

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2011 Juan Romero Pardines.
* Copyright (c) 2008-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -122,6 +122,8 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
for (i = 0; i < prop_array_count(array); i++) {
obj = prop_array_get(array, i);
if (obj == NULL)
continue;
rv = (*fn)(obj, arg, &cbloop_done);
if (rv != 0 || cbloop_done)
break;
@@ -130,6 +132,34 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
return rv;
}
int
xbps_callback_array_iter_reverse(prop_array_t array,
int (*fn)(prop_object_t, void *, bool *),
void *arg)
{
prop_object_t obj;
unsigned int cnt;
int rv;
bool loop_done = false;
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(fn != NULL);
if ((cnt = prop_array_count(array)) == 0)
return 0;
while (cnt--) {
obj = prop_array_get(array, cnt);
if (obj == NULL)
continue;
rv = (*fn)(obj, arg, &loop_done);
if (rv != 0 || loop_done)
break;
}
return rv;
}
int
xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
const char *key,
@@ -137,10 +167,6 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
void *arg)
{
prop_array_t array;
prop_object_t obj;
int rv = 0;
bool cbloop_done = false;
unsigned int cnt = 0;
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
@@ -152,17 +178,7 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
return EINVAL;
}
if ((cnt = prop_array_count(array)) == 0)
return 0;
while (cnt--) {
obj = prop_array_get(array, cnt);
rv = (*fn)(obj, arg, &cbloop_done);
if (rv != 0 || cbloop_done)
break;
}
return rv;
return xbps_callback_array_iter_reverse(array, fn, arg);
}
prop_object_iterator_t
@@ -182,10 +198,11 @@ xbps_array_iter_from_dict(prop_dictionary_t dict, const char *key)
return prop_array_iterator(array);
}
int
xbps_array_replace_dict_by_name(prop_array_t array,
prop_dictionary_t dict,
const char *pkgname)
static int
array_replace_dict(prop_array_t array,
prop_dictionary_t dict,
const char *str,
bool bypattern)
{
prop_object_t obj;
size_t i;
@@ -193,23 +210,54 @@ xbps_array_replace_dict_by_name(prop_array_t array,
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(pkgname != NULL);
assert(str != NULL);
for (i = 0; i < prop_array_count(array); i++) {
obj = prop_array_get(array, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgname);
if (strcmp(curpkgname, pkgname) == 0) {
/* pkgname match, we know the index */
if (!prop_array_set(array, i, dict))
return EINVAL;
if (obj == NULL)
continue;
if (bypattern) {
/* pkgpattern match */
prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &curpkgname);
if (xbps_pkgpattern_match(curpkgname, str)) {
if (!prop_array_set(array, i, dict))
return EINVAL;
return 0;
return 0;
}
} else {
/* pkgname match */
prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &curpkgname);
if (strcmp(curpkgname, str) == 0) {
if (!prop_array_set(array, i, dict))
return EINVAL;
return 0;
}
}
}
/* no match */
return ENOENT;
}
int
xbps_array_replace_dict_by_name(prop_array_t array,
prop_dictionary_t dict,
const char *pkgname)
{
return array_replace_dict(array, dict, pkgname, false);
}
int
xbps_array_replace_dict_by_pattern(prop_array_t array,
prop_dictionary_t dict,
const char *pattern)
{
return array_replace_dict(array, dict, pattern, true);
}
prop_dictionary_t
xbps_dictionary_from_metadata_plist(const char *pkgname,
const char *plist)

View File

@@ -386,10 +386,10 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
assert(str != NULL);
xhp = xbps_handle_get();
if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) {
if ((rv = xbps_pkgdb_init(xhp)) != 0) {
if (rv != ENOENT) {
xbps_dbg_printf("%s: couldn't initialize "
"regpkgdb: %s\n", strerror(rv));
"pkgdb: %s\n", strerror(rv));
return NULL;
} else if (rv == ENOENT)
return NULL;
@@ -397,16 +397,15 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
/* try normal pkg */
if (virtual == false) {
pkgd = find_pkg_in_dict(xhp->regpkgdb,
"packages", str, bypattern, false);
pkgd = find_pkg_in_array(xhp->pkgdb, str, bypattern, false);
} else {
/* virtual pkg set by user in conf */
pkgd = find_virtualpkg_user_in_dict(xhp->regpkgdb,
"packages", str, bypattern);
pkgd = find_virtualpkg_user_in_array(xhp->pkgdb,
str, bypattern);
if (pkgd == NULL) {
/* any virtual pkg in dictionary matching pattern */
pkgd = find_pkg_in_dict(xhp->regpkgdb,
"packages", str, bypattern, true);
/* any virtual pkg in array matching pattern */
pkgd = find_pkg_in_array(xhp->pkgdb,
str, bypattern, true);
}
}
/* pkg not found */

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2011 Juan Romero Pardines.
* Copyright (c) 2008-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@
* all library functions.
*/
static bool
remove_string_from_array(prop_array_t array, const char *str, int mode)
remove_obj_from_array(prop_array_t array, const char *str, int mode)
{
prop_object_iterator_t iter;
prop_object_t obj;
@@ -90,6 +90,14 @@ remove_string_from_array(prop_array_t array, const char *str, int mode)
found = true;
break;
}
} else if (mode == 4) {
/* match by pattern, obj is a dictionary */
prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &curname);
if (xbps_pkgpattern_match(curname, str)) {
found = true;
break;
}
}
idx++;
}
@@ -107,25 +115,31 @@ remove_string_from_array(prop_array_t array, const char *str, int mode)
bool
xbps_remove_string_from_array(prop_array_t array, const char *str)
{
return remove_string_from_array(array, str, 0);
return remove_obj_from_array(array, str, 0);
}
bool
xbps_remove_pkgname_from_array(prop_array_t array, const char *name)
{
return remove_string_from_array(array, name, 1);
return remove_obj_from_array(array, name, 1);
}
bool
xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name)
{
return remove_string_from_array(array, name, 2);
return remove_obj_from_array(array, name, 2);
}
bool
xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, const char *pkgver)
{
return remove_string_from_array(array, pkgver, 3);
return remove_obj_from_array(array, pkgver, 3);
}
bool
xbps_remove_pkg_from_array_by_pattern(prop_array_t array, const char *p)
{
return remove_obj_from_array(array, p, 4);
}
bool

View File

@@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2011 Juan Romero Pardines.
* Copyright (c) 2008-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,66 +31,41 @@
#include "xbps_api_impl.h"
/**
* @file lib/regpkgdb_dictionary.c
* @brief Package register database routines
* @defgroup regpkgdb Package register database functions
*
* These functions will initialize and release (resources of)
* the registered packages database plist file (defined by XBPS_REGPKGDB).
*
* The returned dictionary by xbps_regpkgs_dictionary_init() uses
* the structure as shown in the next graph:
*
* @image html images/xbps_regpkgdb_dictionary.png
*
* Legend:
* - <b>Salmon filled box</b>: \a XBPS_REGPKGDB_PLIST file internalized.
* - <b>White filled box</b>: mandatory objects.
* - <b>Grey filled box</b>: optional objects.
* - <b>Green filled box</b>: possible value set in the object, only one
* of them is set.
*
* Text inside of white boxes are the key associated with the object, its
* data type is specified on its edge, i.e array, bool, integer, string,
* dictionary.
*/
int HIDDEN
xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp)
xbps_pkgdb_init(struct xbps_handle *xhp)
{
int rv;
assert(xhp != NULL);
if (xhp->regpkgdb != NULL)
if (xhp->pkgdb != NULL)
return 0;
rv = xbps_regpkgdb_update(xhp, false);
rv = xbps_pkgdb_update(xhp, false);
if (rv != 0) {
if (rv != ENOENT)
xbps_dbg_printf("[regpkgdb] cannot internalize "
"regpkgdb dictionary: %s\n", strerror(rv));
xbps_dbg_printf("[pkgdb] cannot internalize "
"pkgdb array: %s\n", strerror(rv));
return rv;
}
xbps_dbg_printf("[regpkgdb] initialized ok.\n");
xbps_dbg_printf("[pkgdb] initialized ok.\n");
return 0;
}
int
xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush)
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
{
char *plist, *metadir;
int rv = 0;
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
XBPS_META_PATH, XBPS_PKGDB);
if (plist == NULL)
return ENOMEM;
if (xhp->regpkgdb != NULL && flush) {
if (xhp->pkgdb != NULL && flush) {
metadir = xbps_xasprintf("%s/%s", xhp->rootdir,
XBPS_META_PATH);
if (metadir == NULL) {
@@ -101,7 +76,7 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush)
if (access(metadir, X_OK) == -1) {
if (errno == ENOENT) {
if (xbps_mkpath(metadir, 0755) != 0) {
xbps_dbg_printf("[regpkgdb] failed to "
xbps_dbg_printf("[pkgdb] failed to "
"create metadir %s: %s\n", metadir,
strerror(errno));
rv = errno;
@@ -116,17 +91,16 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush)
}
free(metadir);
/* flush dictionary to storage */
if (!prop_dictionary_externalize_to_zfile(xhp->regpkgdb,
plist)) {
if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) {
free(plist);
return errno;
}
prop_object_release(xhp->regpkgdb);
xhp->regpkgdb = NULL;
prop_object_release(xhp->pkgdb);
xhp->pkgdb = NULL;
}
/* update copy in memory */
xhp->regpkgdb = prop_dictionary_internalize_from_zfile(plist);
if (xhp->regpkgdb == NULL)
xhp->pkgdb = prop_array_internalize_from_zfile(plist);
if (xhp->pkgdb == NULL)
rv = errno;
free(plist);
@@ -135,16 +109,16 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush)
}
void HIDDEN
xbps_regpkgdb_dictionary_release(struct xbps_handle *xhp)
xbps_pkgdb_release(struct xbps_handle *xhp)
{
assert(xhp != NULL);
if (xhp->regpkgdb == NULL)
if (xhp->pkgdb == NULL)
return;
prop_object_release(xhp->regpkgdb);
xhp->regpkgdb = NULL;
xbps_dbg_printf("[regpkgdb] released ok.\n");
prop_object_release(xhp->pkgdb);
xhp->pkgdb = NULL;
xbps_dbg_printf("[pkgdb] released ok.\n");
}
static int
@@ -155,62 +129,96 @@ foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
struct xbps_handle *xhp = xbps_handle_get();
int rv;
/* initialize regpkgdb */
if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0)
if ((rv = xbps_pkgdb_init(xhp)) != 0)
return rv;
if (reverse) {
rv = xbps_callback_array_iter_reverse_in_dict(
xhp->regpkgdb, "packages", fn, arg);
} else {
rv = xbps_callback_array_iter_in_dict(
xhp->regpkgdb, "packages", fn, arg);
}
if (reverse)
rv = xbps_callback_array_iter_reverse(xhp->pkgdb, fn, arg);
else
rv = xbps_callback_array_iter(xhp->pkgdb, fn, arg);
return rv;
}
int
xbps_regpkgdb_foreach_reverse_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
void *arg)
xbps_pkgdb_foreach_reverse_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
void *arg)
{
return foreach_pkg_cb(fn, arg, true);
}
int
xbps_regpkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
void *arg)
xbps_pkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
void *arg)
{
return foreach_pkg_cb(fn, arg, false);
}
prop_dictionary_t
xbps_regpkgdb_get_pkgd(const char *pkg, bool bypattern)
xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = NULL;
if (xbps_regpkgdb_dictionary_init(xhp) != 0)
if (xbps_pkgdb_init(xhp) != 0)
return NULL;
if (bypattern)
pkgd = xbps_find_pkg_in_dict_by_pattern(xhp->regpkgdb,
"packages", pkg);
pkgd = xbps_find_pkg_in_array_by_pattern(xhp->pkgdb, pkg);
else
pkgd = xbps_find_pkg_in_dict_by_name(xhp->regpkgdb,
"packages", pkg);
pkgd = xbps_find_pkg_in_array_by_name(xhp->pkgdb, pkg);
return prop_dictionary_copy(pkgd);
if (pkgd != NULL)
return prop_dictionary_copy(pkgd);
return NULL;
}
bool
xbps_regpkgdb_remove_pkgd(const char *pkgname)
xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush)
{
struct xbps_handle *xhp = xbps_handle_get();
bool rv = false;
if (xbps_regpkgdb_dictionary_init(xhp) != 0)
if (xbps_pkgdb_init(xhp) != 0)
return false;
return xbps_remove_pkg_from_dict_by_name(xhp->regpkgdb,
"packages", pkgname);
if (bypattern)
rv = xbps_remove_pkg_from_array_by_pattern(xhp->pkgdb, pkg);
else
rv = xbps_remove_pkg_from_array_by_name(xhp->pkgdb, pkg);
if (!flush || !rv)
return rv;
if ((xbps_pkgdb_update(xhp, true)) != 0)
return false;
return true;
}
bool
xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
const char *pkg,
bool bypattern,
bool flush)
{
struct xbps_handle *xhp = xbps_handle_get();
int rv;
if (xbps_pkgdb_init(xhp) != 0)
return false;
if (bypattern)
rv = xbps_array_replace_dict_by_pattern(xhp->pkgdb, pkgd, pkg);
else
rv = xbps_array_replace_dict_by_name(xhp->pkgdb, pkgd, pkg);
if (!flush || rv != 0)
return rv;
if ((xbps_pkgdb_update(xhp, true)) != 0)
return false;
return true;
}

View File

@@ -54,10 +54,11 @@ check_repo_arch(const char *uri)
uname(&un);
b = basename(p);
free(p);
if ((strcmp(b, "noarch")) && (strcmp(b, un.machine)))
if ((strcmp(b, "noarch")) && (strcmp(b, un.machine))) {
free(p);
return false;
}
free(p);
return true;
}

View File

@@ -198,7 +198,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if ((xhp->transaction_frequency_flush > 0) &&
(++i >= xhp->transaction_frequency_flush)) {
rv = xbps_regpkgdb_update(xhp, true);
rv = xbps_pkgdb_update(xhp, true);
if (rv != 0 && rv != ENOENT)
goto out;
@@ -274,7 +274,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
prop_object_iterator_reset(iter);
/* force a flush now packages were removed/unpacked */
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0)
if ((rv = xbps_pkgdb_update(xhp, true)) != 0)
goto out;
/* if there are no packages to install or update we are done */
@@ -289,7 +289,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (xhp->transaction_frequency_flush > 0 &&
++i >= xhp->transaction_frequency_flush) {
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0)
if ((rv = xbps_pkgdb_update(xhp, true)) != 0)
goto out;
i = 0;
@@ -323,7 +323,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
}
/* Force a flush now that packages are configured */
rv = xbps_regpkgdb_update(xhp, true);
rv = xbps_pkgdb_update(xhp, true);
out:
prop_object_iterator_release(iter);

View File

@@ -59,7 +59,7 @@ enum {
static int
transaction_find_pkg(const char *pattern, int action)
{
prop_dictionary_t pkg_regpkgdb, pkg_repod = NULL;
prop_dictionary_t pkg_pkgdb, pkg_repod = NULL;
prop_dictionary_t transd;
prop_array_t mdeps, unsorted;
const char *pkgname, *pkgver, *repoloc, *repover, *instver, *reason;
@@ -76,8 +76,8 @@ transaction_find_pkg(const char *pattern, int action)
reason = "install";
} else {
/* update */
pkg_regpkgdb = xbps_find_pkg_dict_installed(pattern, false);
if (pkg_regpkgdb == NULL) {
pkg_pkgdb = xbps_find_pkg_dict_installed(pattern, false);
if (pkg_pkgdb == NULL) {
rv = ENODEV;
goto out;
}
@@ -109,11 +109,11 @@ transaction_find_pkg(const char *pattern, int action)
/*
* Compare installed version vs best pkg available in repos.
*/
prop_dictionary_get_cstring_nocopy(pkg_regpkgdb,
prop_dictionary_get_cstring_nocopy(pkg_pkgdb,
"version", &instver);
prop_dictionary_get_cstring_nocopy(pkg_repod,
"version", &repover);
prop_object_release(pkg_regpkgdb);
prop_object_release(pkg_pkgdb);
if (xbps_cmpver(repover, instver) <= 0) {
xbps_dbg_printf("[rpool] Skipping `%s' "
"(installed: %s) from repository `%s'\n",
@@ -227,7 +227,7 @@ xbps_transaction_update_packages(void)
bool newpkg_found = false;
int rv;
rv = xbps_regpkgdb_foreach_pkg_cb(update_pkgs_cb, &newpkg_found);
rv = xbps_pkgdb_foreach_pkg_cb(update_pkgs_cb, &newpkg_found);
if (!newpkg_found)
rv = EEXIST;
@@ -258,7 +258,7 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
assert(pkgname != NULL);
if ((pkgd = xbps_regpkgdb_get_pkgd(pkgname, false)) == NULL) {
if ((pkgd = xbps_pkgdb_get_pkgd(pkgname, false)) == NULL) {
/* pkg not installed */
return ENOENT;
}