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

@ -28,7 +28,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h> #include <sys/param.h>
@ -38,6 +37,7 @@
struct checkpkg { struct checkpkg {
size_t npkgs; size_t npkgs;
size_t nbrokenpkgs; size_t nbrokenpkgs;
bool flush;
}; };
static int static int
@ -45,15 +45,17 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
{ {
struct checkpkg *cpkg = arg; struct checkpkg *cpkg = arg;
const char *pkgname, *version; const char *pkgname, *version;
bool flush = false;
(void)done; (void)done;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version); prop_dictionary_get_cstring_nocopy(obj, "version", &version);
printf("Checking %s-%s ...\n", pkgname, version); printf("Checking %s-%s ...\n", pkgname, version);
if (check_pkg_integrity(obj, pkgname) != 0) if (check_pkg_integrity(obj, pkgname, false, &flush) != 0)
cpkg->nbrokenpkgs++; cpkg->nbrokenpkgs++;
cpkg->flush = flush;
cpkg->npkgs++; cpkg->npkgs++;
return 0; return 0;
} }
@ -61,26 +63,33 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
int int
check_pkg_integrity_all(void) check_pkg_integrity_all(void)
{ {
struct checkpkg *cpkg; struct xbps_handle *xhp = xbps_handle_get();
struct checkpkg cpkg;
cpkg = calloc(1, sizeof(*cpkg)); int rv;
if (cpkg == NULL)
return ENOMEM;
(void)xbps_regpkgdb_foreach_pkg_cb(cb_pkg_integrity, cpkg);
printf("%zu package%s processed: %zu broken.\n", cpkg->npkgs,
cpkg->npkgs == 1 ? "" : "s", cpkg->nbrokenpkgs);
free(cpkg);
memset(&cpkg, 0, sizeof(cpkg));
(void)xbps_pkgdb_foreach_pkg_cb(cb_pkg_integrity, &cpkg);
if (cpkg.flush) {
if ((rv = xbps_pkgdb_update(xhp, true)) != 0) {
xbps_error_printf("failed to write pkgdb: %s\n",
strerror(rv));
return rv;
}
}
printf("%zu package%s processed: %zu broken.\n", cpkg.npkgs,
cpkg.npkgs == 1 ? "" : "s", cpkg.nbrokenpkgs);
return 0; return 0;
} }
int int
check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname) check_pkg_integrity(prop_dictionary_t pkgd,
const char *pkgname,
bool flush,
bool *setflush)
{ {
prop_dictionary_t opkgd, propsd, filesd; prop_dictionary_t opkgd, propsd, filesd;
int rv = 0; int rv = 0;
bool broken = false; bool pkgdb_update = false, broken = false;
propsd = filesd = opkgd = NULL; propsd = filesd = opkgd = NULL;
@ -101,7 +110,7 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname)
* Check for props.plist metadata file. * Check for props.plist metadata file.
*/ */
propsd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGPROPS); propsd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGPROPS);
if (prop_object_type(propsd) != PROP_TYPE_DICTIONARY) { if (propsd == NULL) {
xbps_error_printf("%s: unexistent %s or invalid metadata " xbps_error_printf("%s: unexistent %s or invalid metadata "
"file.\n", pkgname, XBPS_PKGPROPS); "file.\n", pkgname, XBPS_PKGPROPS);
broken = true; broken = true;
@ -116,7 +125,7 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname)
* Check for files.plist metadata file. * Check for files.plist metadata file.
*/ */
filesd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES); filesd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
if (prop_object_type(filesd) != PROP_TYPE_DICTIONARY) { if (filesd == NULL) {
xbps_error_printf("%s: unexistent %s or invalid metadata " xbps_error_printf("%s: unexistent %s or invalid metadata "
"file.\n", pkgname, XBPS_PKGFILES); "file.\n", pkgname, XBPS_PKGFILES);
broken = true; broken = true;
@ -128,9 +137,9 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname)
goto out; goto out;
} }
#define RUN_PKG_CHECK(name, arg) \ #define RUN_PKG_CHECK(name, arg, arg2) \
do { \ do { \
rv = check_pkg_##name(pkgname, arg); \ rv = check_pkg_##name(pkgname, arg, arg2); \
if (rv) \ if (rv) \
broken = true; \ broken = true; \
else if (rv == -1) { \ else if (rv == -1) { \
@ -141,11 +150,20 @@ do { \
} while (0) } while (0)
/* Execute pkg checks */ /* Execute pkg checks */
RUN_PKG_CHECK(requiredby, pkgd ? pkgd : opkgd); RUN_PKG_CHECK(requiredby, pkgd ? pkgd : opkgd, &pkgdb_update);
RUN_PKG_CHECK(autoinstall, pkgd ? pkgd : opkgd); RUN_PKG_CHECK(autoinstall, pkgd ? pkgd : opkgd, &pkgdb_update);
RUN_PKG_CHECK(files, filesd); RUN_PKG_CHECK(files, filesd, &pkgdb_update);
RUN_PKG_CHECK(symlinks, filesd); RUN_PKG_CHECK(symlinks, filesd, &pkgdb_update);
RUN_PKG_CHECK(rundeps, propsd); RUN_PKG_CHECK(rundeps, propsd, &pkgdb_update);
if (flush && pkgdb_update) {
if (!xbps_pkgdb_replace_pkgd(opkgd, pkgname, false, true)) {
rv = EINVAL;
goto out;
}
}
if (pkgdb_update && setflush != NULL)
*setflush = true;
#undef RUN_PKG_CHECK #undef RUN_PKG_CHECK

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2011 Juan Romero Pardines. * Copyright (c) 2011-2012 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -47,12 +47,10 @@
* Returns 0 if test ran successfully, 1 otherwise and -1 on error. * Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
int int
check_pkg_autoinstall(const char *pkgname, void *arg) check_pkg_autoinstall(const char *pkgname, void *arg, bool *pkgdb_update)
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = arg; prop_dictionary_t pkgd = arg;
prop_array_t array, reqby; prop_array_t reqby;
int rv = 0;
bool autoinst = false; bool autoinst = false;
/* /*
@ -62,39 +60,14 @@ check_pkg_autoinstall(const char *pkgname, void *arg)
*/ */
if (prop_dictionary_get_bool(pkgd, "automatic-install", &autoinst)) { if (prop_dictionary_get_bool(pkgd, "automatic-install", &autoinst)) {
reqby = prop_dictionary_get(pkgd, "requiredby"); reqby = prop_dictionary_get(pkgd, "requiredby");
if (((prop_object_type(reqby) == PROP_TYPE_ARRAY)) && if (reqby != NULL && prop_array_count(reqby) && !autoinst) {
((prop_array_count(reqby) > 0) && !autoinst)) {
/* pkg has reversedeps and was installed manually */ /* pkg has reversedeps and was installed manually */
prop_dictionary_set_bool(pkgd, prop_dictionary_set_bool(pkgd,
"automatic-install", true); "automatic-install", true);
*pkgdb_update = true;
array = prop_dictionary_get(xhp->regpkgdb, "packages"); printf("%s: changed to automatic install mode.\n",
rv = xbps_array_replace_dict_by_name(array, pkgname);
pkgd, pkgname);
if (rv != 0) {
xbps_error_printf("%s: [1] failed to set "
"automatic mode (%s)\n", pkgname,
strerror(rv));
return -1;
}
if (!prop_dictionary_set(xhp->regpkgdb,
"packages", array)) {
xbps_error_printf("%s: [2] failed to set "
"automatic mode (%s)\n", pkgname,
strerror(rv));
return -1;
}
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) {
xbps_error_printf("%s: failed to write "
"regpkgdb plist: %s\n", pkgname,
strerror(rv));
return -1;
}
xbps_warn_printf("%s: was installed manually and has "
"reverse dependencies (FIXED)\n", pkgname);
} }
} }
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2011 Juan Romero Pardines. * Copyright (c) 2011-2012 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -28,7 +28,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h> #include <sys/param.h>
@ -47,7 +46,7 @@
* Return 0 if test ran successfully, 1 otherwise and -1 on error. * Return 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
int int
check_pkg_files(const char *pkgname, void *arg) check_pkg_files(const char *pkgname, void *arg, bool *pkgdb_update)
{ {
struct xbps_handle *xhp = xbps_handle_get(); struct xbps_handle *xhp = xbps_handle_get();
prop_array_t array; prop_array_t array;
@ -59,9 +58,10 @@ check_pkg_files(const char *pkgname, void *arg)
int rv = 0; int rv = 0;
bool broken = false, test_broken = false; bool broken = false, test_broken = false;
(void)pkgdb_update;
array = prop_dictionary_get(pkg_filesd, "files"); array = prop_dictionary_get(pkg_filesd, "files");
if ((prop_object_type(array) == PROP_TYPE_ARRAY) && if (array != NULL && prop_array_count(array) > 0) {
prop_array_count(array) > 0) {
iter = xbps_array_iter_from_dict(pkg_filesd, "files"); iter = xbps_array_iter_from_dict(pkg_filesd, "files");
if (iter == NULL) if (iter == NULL)
return -1; return -1;
@ -109,8 +109,7 @@ check_pkg_files(const char *pkgname, void *arg)
* Check for missing configuration files. * Check for missing configuration files.
*/ */
array = prop_dictionary_get(pkg_filesd, "conf_files"); array = prop_dictionary_get(pkg_filesd, "conf_files");
if (array && prop_object_type(array) == PROP_TYPE_ARRAY && if (array != NULL && prop_array_count(array) > 0) {
prop_array_count(array) > 0) {
iter = xbps_array_iter_from_dict(pkg_filesd, "conf_files"); iter = xbps_array_iter_from_dict(pkg_filesd, "conf_files");
if (iter == NULL) if (iter == NULL)
return -1; return -1;

View File

@ -28,44 +28,37 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h> #include <sys/param.h>
#include <xbps_api.h> #include <xbps_api.h>
#include "defs.h" #include "defs.h"
/* struct check_reqby_data {
* Checks package integrity of an installed package. prop_dictionary_t pkgd;
* The following task is accomplished in this file: prop_array_t pkgd_reqby;
* const char *pkgname;
* o Check for missing reverse dependencies (aka requiredby) const char *pkgver;
* entries in pkg's regpkgdb dictionary. bool pkgdb_update;
* bool pkgd_reqby_alloc;
* Returns 0 if test ran successfully, 1 otherwise and -1 on error. };
*/
int static int
check_pkg_requiredby(const char *pkgname, void *arg) check_reqby_pkg_cb(prop_object_t obj, void *arg, bool *done)
{ {
prop_array_t regpkgs, reqby, curpkg_rdeps, provides; struct check_reqby_data *crd = arg;
prop_dictionary_t curpkg_propsd, pkgd = arg; prop_array_t curpkg_rdeps, provides;
prop_object_t obj; prop_dictionary_t curpkg_propsd;
prop_string_t curpkgver; prop_string_t curpkgver;
struct xbps_handle *xhp = xbps_handle_get(); const char *curpkgn;
const char *curpkgn, *pkgver;
size_t i;
int rv;
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); (void)done;
regpkgs = prop_dictionary_get(xhp->regpkgdb, "packages");
for (i = 0; i < prop_array_count(regpkgs); i++) {
obj = prop_array_get(regpkgs, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgn); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgn);
/* skip same pkg */ /* skip same pkg */
if (strcmp(curpkgn, pkgname) == 0) if (strcmp(curpkgn, crd->pkgname) == 0)
continue; return 0;
/* /*
* Internalize current pkg props dictionary from its * Internalize current pkg props dictionary from its
* installed metadata directory. * installed metadata directory.
@ -79,84 +72,108 @@ check_pkg_requiredby(const char *pkgname, void *arg)
} }
curpkg_rdeps = curpkg_rdeps =
prop_dictionary_get(curpkg_propsd, "run_depends"); prop_dictionary_get(curpkg_propsd, "run_depends");
if (prop_object_type(curpkg_rdeps) != PROP_TYPE_ARRAY) { if (curpkg_rdeps == NULL) {
/* package has no rundeps, skip */ /* package has no rundeps, skip */
prop_object_release(curpkg_propsd); prop_object_release(curpkg_propsd);
continue; return 0;
} }
/* /*
* Check for pkgpattern match with real packages... * Check for pkgpattern match with real packages...
*/ */
if (!xbps_match_pkgdep_in_array(curpkg_rdeps, pkgver)) { if (!xbps_match_pkgdep_in_array(curpkg_rdeps, crd->pkgver)) {
/* /*
* ... otherwise check if package provides any virtual * ... otherwise check if package provides any virtual
* package and is matched against any object in * package and is matched against any object in
* run_depends. * run_depends.
*/ */
provides = prop_dictionary_get(pkgd, "provides"); provides = prop_dictionary_get(obj, "provides");
if (prop_object_type(provides) != PROP_TYPE_ARRAY) { if (provides == NULL) {
/* doesn't provide any virtual pkg */ /* doesn't provide any virtual pkg */
prop_object_release(curpkg_propsd); prop_object_release(curpkg_propsd);
continue; return 0;
} }
if (!xbps_match_any_virtualpkg_in_rundeps(curpkg_rdeps, if (!xbps_match_any_virtualpkg_in_rundeps(curpkg_rdeps,
provides)) { provides)) {
/* doesn't match any virtual pkg */ /* doesn't match any virtual pkg */
prop_object_release(curpkg_propsd); prop_object_release(curpkg_propsd);
continue; return 0;
} }
} }
reqby = prop_dictionary_get(pkgd, "requiredby"); crd->pkgd_reqby = prop_dictionary_get(crd->pkgd, "requiredby");
curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver"); curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver");
if (prop_object_type(reqby) == PROP_TYPE_ARRAY) { if (crd->pkgd_reqby != NULL) {
/* /*
* Now check that current pkgver has been registered into * Now check that current pkgver has been registered into
* its requiredby array. * its requiredby array.
*/ */
if (xbps_match_string_in_array(reqby, if (xbps_match_string_in_array(crd->pkgd_reqby,
prop_string_cstring_nocopy(curpkgver))) { prop_string_cstring_nocopy(curpkgver))) {
/* /*
* Current package already requires our package, * Current package already requires our package,
* this is good so skip it. * this is good so skip it.
*/ */
prop_object_release(curpkg_propsd); prop_object_release(curpkg_propsd);
continue; return 0;
} }
} else { } else {
/* /*
* Missing requiredby array object, create it. * Missing requiredby array object, create it.
*/ */
reqby = prop_array_create(); crd->pkgd_reqby = prop_array_create();
if (reqby == NULL) { if (crd->pkgd_reqby == NULL) {
prop_object_release(curpkg_propsd); prop_object_release(curpkg_propsd);
return -1; return -1;
} }
crd->pkgd_reqby_alloc = true;
} }
/* /*
* Replace current obj in regpkgdb and write new plist * Added pkgdep into pkg's requiredby array.
* file to disk.
*/ */
prop_array_add(reqby, curpkgver); if (!prop_array_add(crd->pkgd_reqby, curpkgver)) {
prop_dictionary_set(pkgd, "requiredby", reqby);
rv = xbps_array_replace_dict_by_name(regpkgs, obj, curpkgn);
if (rv != 0) {
xbps_error_printf("%s: failed to replace pkgd: %s\n",
curpkgn, strerror(rv));
return -1;
}
if (!prop_dictionary_set(xhp->regpkgdb, "packages", regpkgs)) {
xbps_error_printf("%s: failed to set new regpkgdb "
"packages array: %s", curpkgn, strerror(errno));
return -1;
}
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) {
xbps_error_printf("failed to write regpkgdb plist: "
" %s\n", strerror(rv));
return rv;
}
printf("%s: added requiredby entry for %s.\n",
pkgver, prop_string_cstring_nocopy(curpkgver));
prop_object_release(curpkg_propsd); prop_object_release(curpkg_propsd);
return -1;
} }
printf("%s: added missing requiredby entry for %s.\n",
crd->pkgname, prop_string_cstring_nocopy(curpkgver));
prop_object_release(curpkg_propsd);
crd->pkgdb_update = true;
return 0;
}
/*
* Checks package integrity of an installed package.
* The following task is accomplished in this file:
*
* o Check for missing reverse dependencies (aka requiredby)
* entries in pkg's pkgdb dictionary.
*
* Returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/
int
check_pkg_requiredby(const char *pkgname, void *arg, bool *pkgdb_update)
{
struct check_reqby_data crd;
int rv;
crd.pkgd = arg;
crd.pkgd_reqby = NULL;
crd.pkgd_reqby_alloc = false;
crd.pkgname = pkgname;
crd.pkgdb_update = false;
prop_dictionary_get_cstring_nocopy(crd.pkgd, "pkgver", &crd.pkgver);
rv = xbps_pkgdb_foreach_pkg_cb(check_reqby_pkg_cb, &crd);
*pkgdb_update = crd.pkgdb_update;
if (crd.pkgdb_update) {
if (!prop_dictionary_set(crd.pkgd, "requiredby", crd.pkgd_reqby))
rv = -1;
if (crd.pkgd_reqby_alloc)
prop_object_release(crd.pkgd_reqby);
}
if (rv != 0)
*pkgdb_update = false;
return rv; return rv;
} }

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2011 Juan Romero Pardines. * Copyright (c) 2011-2012 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,7 +45,7 @@
*/ */
int int
check_pkg_rundeps(const char *pkgname, void *arg) check_pkg_rundeps(const char *pkgname, void *arg, bool *pkgdb_update)
{ {
prop_dictionary_t pkg_propsd = arg; prop_dictionary_t pkg_propsd = arg;
prop_object_t obj; prop_object_t obj;
@ -53,6 +53,8 @@ check_pkg_rundeps(const char *pkgname, void *arg)
const char *reqpkg; const char *reqpkg;
bool test_broken = false; bool test_broken = false;
(void)pkgdb_update;
if (!xbps_pkg_has_rundeps(pkg_propsd)) if (!xbps_pkg_has_rundeps(pkg_propsd))
return 0; return 0;

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2011 Juan Romero Pardines. * Copyright (c) 2011-2012 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,7 +45,7 @@
* returns 0 if test ran successfully, 1 otherwise and -1 on error. * returns 0 if test ran successfully, 1 otherwise and -1 on error.
*/ */
int int
check_pkg_symlinks(const char *pkgname, void *arg) check_pkg_symlinks(const char *pkgname, void *arg, bool *pkgdb_update)
{ {
const struct xbps_handle *xhp = xbps_handle_get(); const struct xbps_handle *xhp = xbps_handle_get();
prop_array_t array; prop_array_t array;
@ -56,6 +56,8 @@ check_pkg_symlinks(const char *pkgname, void *arg)
char *path, buf[PATH_MAX]; char *path, buf[PATH_MAX];
bool broken = false, test_broken = false; bool broken = false, test_broken = false;
(void)pkgdb_update;
array = prop_dictionary_get(pkg_filesd, "links"); array = prop_dictionary_get(pkg_filesd, "links");
if ((prop_object_type(array) == PROP_TYPE_ARRAY) && if ((prop_object_type(array) == PROP_TYPE_ARRAY) &&
prop_array_count(array) > 0) { prop_array_count(array) > 0) {

View File

@ -56,11 +56,11 @@ int exec_transaction(bool, bool);
int remove_installed_pkgs(int, char **, bool, bool, bool, bool); int remove_installed_pkgs(int, char **, bool, bool, bool, bool);
/* from check.c */ /* from check.c */
int check_pkg_integrity(prop_dictionary_t, const char *); int check_pkg_integrity(prop_dictionary_t, const char *, bool, bool *);
int check_pkg_integrity_all(void); int check_pkg_integrity_all(void);
#define CHECK_PKG_DECL(type) \ #define CHECK_PKG_DECL(type) \
int check_pkg_##type (const char *, void *) int check_pkg_##type (const char *, void *, bool *)
CHECK_PKG_DECL(autoinstall); CHECK_PKG_DECL(autoinstall);
CHECK_PKG_DECL(files); CHECK_PKG_DECL(files);

View File

@ -203,7 +203,7 @@ main(int argc, char **argv)
* Find the longest pkgver string to pretty print the output. * Find the longest pkgver string to pretty print the output.
*/ */
lpc.pkgver_len = find_longest_pkgver(NULL); lpc.pkgver_len = find_longest_pkgver(NULL);
rv = xbps_regpkgdb_foreach_pkg_cb(list_pkgs_in_dict, &lpc); rv = xbps_pkgdb_foreach_pkg_cb(list_pkgs_in_dict, &lpc);
if (rv == ENOENT) { if (rv == ENOENT) {
printf("No packages currently registered.\n"); printf("No packages currently registered.\n");
rv = 0; rv = 0;
@ -281,7 +281,7 @@ main(int argc, char **argv)
if (strcasecmp(argv[1], "all") == 0) if (strcasecmp(argv[1], "all") == 0)
rv = check_pkg_integrity_all(); rv = check_pkg_integrity_all();
else else
rv = check_pkg_integrity(NULL, argv[1]); rv = check_pkg_integrity(NULL, argv[1], true, NULL);
} else if (strcasecmp(argv[0], "autoupdate") == 0) { } else if (strcasecmp(argv[0], "autoupdate") == 0) {
/* /*
@ -342,7 +342,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
rv = xbps_regpkgdb_foreach_pkg_cb(list_manual_pkgs, NULL); rv = xbps_pkgdb_foreach_pkg_cb(list_manual_pkgs, NULL);
} else if (strcasecmp(argv[0], "show-revdeps") == 0) { } else if (strcasecmp(argv[0], "show-revdeps") == 0) {
/* /*

View File

@ -28,7 +28,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <fnmatch.h> #include <fnmatch.h>
#include <assert.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
@ -88,9 +87,6 @@ show_pkg_info_one(prop_dictionary_t d, const char *keys)
prop_object_t obj; prop_object_t obj;
char *key, *p, *saveptr; char *key, *p, *saveptr;
assert(prop_object_type(d) == PROP_TYPE_DICTIONARY);
assert(keys != NULL);
if (strchr(keys, ',') == NULL) { if (strchr(keys, ',') == NULL) {
obj = prop_dictionary_get(d, keys); obj = prop_dictionary_get(d, keys);
if (obj == NULL) if (obj == NULL)
@ -99,7 +95,8 @@ show_pkg_info_one(prop_dictionary_t d, const char *keys)
return; return;
} }
key = strdup(keys); key = strdup(keys);
assert(key != NULL); if (key == NULL)
abort();
for ((p = strtok_r(key, ",", &saveptr)); p; for ((p = strtok_r(key, ",", &saveptr)); p;
(p = strtok_r(NULL, ",", &saveptr))) { (p = strtok_r(NULL, ",", &saveptr))) {
obj = prop_dictionary_get(d, p); obj = prop_dictionary_get(d, p);
@ -118,9 +115,6 @@ show_pkg_info(prop_dictionary_t dict)
const char *keyname; const char *keyname;
size_t i; size_t i;
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(prop_dictionary_count(dict) != 0);
all_keys = prop_dictionary_all_keys(dict); all_keys = prop_dictionary_all_keys(dict);
for (i = 0; i < prop_array_count(all_keys); i++) { for (i = 0; i < prop_array_count(all_keys); i++) {
keysym = prop_array_get(all_keys, i); keysym = prop_array_get(all_keys, i);
@ -151,8 +145,7 @@ show_pkg_files(prop_dictionary_t filesd)
continue; continue;
array = prop_dictionary_get(filesd, keyname); array = prop_dictionary_get(filesd, keyname);
if (prop_object_type(array) != PROP_TYPE_ARRAY || if (array == NULL || prop_array_count(array) == 0)
prop_array_count(array) == 0)
continue; continue;
for (x = 0; x < prop_array_count(array); x++) { for (x = 0; x < prop_array_count(array); x++) {
@ -194,7 +187,7 @@ find_longest_pkgver(prop_object_t o)
(void)xbps_callback_array_iter(o, (void)xbps_callback_array_iter(o,
_find_longest_pkgver_cb, &len); _find_longest_pkgver_cb, &len);
else else
(void)xbps_regpkgdb_foreach_pkg_cb( (void)xbps_pkgdb_foreach_pkg_cb(
_find_longest_pkgver_cb, &len); _find_longest_pkgver_cb, &len);
return len; return len;
@ -206,7 +199,6 @@ list_strings_in_array(prop_object_t obj, void *arg, bool *loop_done)
(void)arg; (void)arg;
(void)loop_done; (void)loop_done;
assert(prop_object_type(obj) == PROP_TYPE_STRING);
print_package_line(prop_string_cstring_nocopy(obj), false); print_package_line(prop_string_cstring_nocopy(obj), false);
return 0; return 0;
@ -219,7 +211,6 @@ list_strings_sep_in_array(prop_object_t obj, void *arg, bool *loop_done)
(void)loop_done; (void)loop_done;
assert(prop_object_type(obj) == PROP_TYPE_STRING);
printf("%s%s\n", sep ? sep : "", prop_string_cstring_nocopy(obj)); printf("%s%s\n", sep ? sep : "", prop_string_cstring_nocopy(obj));
return 0; return 0;

View File

@ -1,4 +1,4 @@
.Dd January 5, 2012 .Dd January 19, 2012
.Os Void GNU/Linux .Os Void GNU/Linux
.Dt xbps-bin 8 .Dt xbps-bin 8
.Sh NAME .Sh NAME
@ -254,8 +254,8 @@ XBPS global metadata directory.
Installed package metadata list of files. Installed package metadata list of files.
.It Pa /var/db/xbps/metadata/<pkgname>/props.plist .It Pa /var/db/xbps/metadata/<pkgname>/props.plist
Installed package metadata properties. Installed package metadata properties.
.It Pa /var/db/xbps/regpkgdb.plist .It Pa /var/db/xbps/pkgdb.plist
XBPS master packages/properties database plist file. XBPS master package database plist file.
.It Pa /var/cache/xbps .It Pa /var/cache/xbps
XBPS cache directory for downloaded binary packages. XBPS cache directory for downloaded binary packages.
.Sh EXAMPLES .Sh EXAMPLES

View File

@ -235,7 +235,7 @@ static void
parse_array_in_pkg_dictionary(FILE *f, prop_dictionary_t plistd, parse_array_in_pkg_dictionary(FILE *f, prop_dictionary_t plistd,
prop_dictionary_t sub_confd, prop_dictionary_t sub_confd,
prop_array_t allkeys, prop_array_t allkeys,
bool parse_regpkgdb) bool parse_pkgdb)
{ {
prop_dictionary_keysym_t dksym; prop_dictionary_keysym_t dksym;
prop_object_t keyobj, sub_keyobj; prop_object_t keyobj, sub_keyobj;
@ -248,11 +248,11 @@ parse_array_in_pkg_dictionary(FILE *f, prop_dictionary_t plistd,
tmpkeyname = prop_dictionary_keysym_cstring_nocopy(dksym); tmpkeyname = prop_dictionary_keysym_cstring_nocopy(dksym);
/* /*
* While parsing package's dictionary from regpkgdb, we are * While parsing package's dictionary from pkgdb, we are
* only interested in the "automatic-install" and "requiredby" * only interested in the "automatic-install" and "requiredby"
* objects. * objects.
*/ */
if (parse_regpkgdb && if (parse_pkgdb &&
(strcmp(tmpkeyname, "automatic-install")) && (strcmp(tmpkeyname, "automatic-install")) &&
(strcmp(tmpkeyname, "requiredby"))) (strcmp(tmpkeyname, "requiredby")))
continue; continue;
@ -418,14 +418,14 @@ create_dot_graph(FILE *f,
parse_array_in_pkg_dictionary(f, plistd, sub_confd, allkeys, false); parse_array_in_pkg_dictionary(f, plistd, sub_confd, allkeys, false);
/* /*
* Process all objects in package's dictionary from regpkgdb property * Process all objects in package's dictionary from pkgdb property
* list file, aka XBPS_META_PATH/XBPS_REGPKGDB. * list file, aka XBPS_META_PATH/XBPS_PKGDB.
*/ */
if (revdeps) { if (revdeps) {
regpkgd = xbps_find_pkg_dict_installed(pkgn, false); regpkgd = xbps_find_pkg_dict_installed(pkgn, false);
if (regpkgd == NULL) if (regpkgd == NULL)
die("cannot find '%s' dictionary on %s!", die("cannot find '%s' dictionary on %s!",
pkgn, XBPS_REGPKGDB); pkgn, XBPS_PKGDB);
allkeys = prop_dictionary_all_keys(regpkgd); allkeys = prop_dictionary_all_keys(regpkgd);
parse_array_in_pkg_dictionary(f, regpkgd, sub_confd, parse_array_in_pkg_dictionary(f, regpkgd, sub_confd,

View File

@ -38,7 +38,6 @@
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <libgen.h> #include <libgen.h>
#include <assert.h>
#include <xbps_api.h> #include <xbps_api.h>
#include "../xbps-bin/defs.h" #include "../xbps-bin/defs.h"
@ -100,9 +99,6 @@ show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
(void)loop_done; (void)loop_done;
assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY);
assert(rsd->patterns != NULL);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc); prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);

View File

@ -188,7 +188,7 @@ main(int argc, char **argv)
prop_dictionary_set_cstring(dict, "pkgver", pkgver); prop_dictionary_set_cstring(dict, "pkgver", pkgver);
prop_dictionary_set_bool(dict, "automatic-install", false); prop_dictionary_set_bool(dict, "automatic-install", false);
pkgd = xbps_regpkgdb_get_pkgd(argv[1], false); pkgd = xbps_pkgdb_get_pkgd(argv[1], false);
if (pkgd != NULL) { if (pkgd != NULL) {
prop_dictionary_get_cstring_nocopy(pkgd, prop_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &pkgn); "pkgname", &pkgn);
@ -244,7 +244,7 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
dict = xbps_regpkgdb_get_pkgd(argv[1], false); dict = xbps_pkgdb_get_pkgd(argv[1], false);
if (dict == NULL) { if (dict == NULL) {
rv = errno; rv = errno;
goto out; goto out;

View File

@ -1,13 +1,12 @@
digraph regpkgdb_dictionary { digraph pkgdb_array {
graph [rankdir=LR,rank=same,ranksep=".10"]; graph [rankdir=LR,rank=same,ranksep=".10"];
edge [arrowhead="vee",arrowsize="0.2",fontname="DejaVuSansCondensed",fontsize="9"]; edge [arrowhead="vee",arrowsize="0.2",fontname="DejaVuSansCondensed",fontsize="9"];
node [height=".1",shape=box,fontname="DejaVuSansCondensed",fontsize="9"]; node [height=".1",shape=box,fontname="DejaVuSansCondensed",fontsize="9"];
regpkgdb_plist -> main; pkgdb_plist -> main;
regpkgdb_plist [style=filled,fillcolor="darksalmon",label="regpkgdb.plist"]; pkgdb_plist [style=filled,fillcolor="darksalmon",label="pkgdb.plist"];
main [label="Main dictionary"]; main [label="Main array"];
main -> packages [label="array"]; main -> pkgdict [label="dictionary"];
packages -> pkgdict [label="dictionary"]; main -> pkgdict2 [label="dictionary"];
packages -> pkgdict2 [label="dictionary"];
pkgdict [style=filled,label="Package[0]"]; pkgdict [style=filled,label="Package[0]"];
pkgdict2 [style=filled,label="Package[N+1]"]; pkgdict2 [style=filled,label="Package[N+1]"];
pkgdict2 -> pkgdict2_objs [label="objects"]; pkgdict2 -> pkgdict2_objs [label="objects"];

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.4" #define XBPS_PKGINDEX_VERSION "1.4"
#define XBPS_API_VERSION "20120119" #define XBPS_API_VERSION "20120120"
#define XBPS_VERSION "0.12" #define XBPS_VERSION "0.12"
/** /**
@ -80,10 +80,10 @@
#define XBPS_CACHE_PATH "var/cache/xbps" #define XBPS_CACHE_PATH "var/cache/xbps"
/** /**
* @def XBPS_REGPKGDB * @def XBPS_PKGDB
* Filename for the global package register database. * Filename for the master package database.
*/ */
#define XBPS_REGPKGDB "regpkgdb.plist" #define XBPS_PKGDB "pkgdb.plist"
/** /**
* @def XBPS_PKGPROPS * @def XBPS_PKGPROPS
@ -428,19 +428,19 @@ struct xbps_handle {
* @private * @private
*/ */
cfg_t *cfg; cfg_t *cfg;
/**
* @private regpkgdb.
*
* Internalized proplib dictionary with the registed package database
* stored in XBPS_META_PATH/XBPS_REGPKGDB.
*/
prop_dictionary_t regpkgdb;
/** /**
* @private * @private
* *
* Array of dictionaries with all registered repositories. * Array of dictionaries with all registered repositories.
*/ */
prop_array_t repo_pool; prop_array_t repo_pool;
/**
* @private pkgdb.
*
* Internalized proplib array with the master package database
* stored in XBPS_META_PATH/XBPS_PKGDB.
*/
prop_array_t pkgdb;
/** /**
* @var xbps_state_cb * @var xbps_state_cb
* *
@ -601,7 +601,7 @@ struct xbps_handle *xbps_handle_get(void);
* @param[in] check_state Set it to true to check that package is * @param[in] check_state Set it to true to check that package is
* in unpacked state. * in unpacked state.
* @param[in] update Set it to true if this package is being updated. * @param[in] update Set it to true if this package is being updated.
* @param[in] flush Set it to true to flush state to regpkgdb. * @param[in] flush Set it to true to flush state to pkgdb.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
@ -613,7 +613,7 @@ int xbps_configure_pkg(const char *pkgname,
/** /**
* Configure (or force reconfiguration of) all packages. * Configure (or force reconfiguration of) all packages.
* @param[in] flush Set it to true to flush state to regpkgdb. * @param[in] flush Set it to true to flush state to pkgdb.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
@ -739,6 +739,23 @@ int xbps_callback_array_iter(prop_array_t array,
int (*fn)(prop_object_t, void *, bool *), int (*fn)(prop_object_t, void *, bool *),
void *arg); void *arg);
/**
* Executes a function callback specified in \a fn with \a arg passed
* as its argument into they array \a array in reverse order (upwards).
*
* @param[in] array Proplib array to iterate.
* @param[in] fn Function callback to run on every object in the array.
* While running the function callback, the hird parameter (a pointer to
* a boolean) can be set to true to stop immediately the loop.
* @param[in] arg Argument to be passed to the function callback.
*
* @return 0 on success, otherwise the value returned by the function
* callback.
*/
int xbps_callback_array_iter_reverse(prop_array_t array,
int (*fn)(prop_object_t, void *, bool *),
void *arg);
/** /**
* Executes a function callback into the array associated with key \a key, * Executes a function callback into the array associated with key \a key,
* contained in a proplib dictionary. * contained in a proplib dictionary.
@ -781,7 +798,7 @@ int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
/** /**
* Executes a function callback per a package dictionary registered * Executes a function callback per a package dictionary registered
* in "regpkgdb" plist (downwards). * in master package database (pkgdb) plist (downwards).
* *
* @param[in] fn Function callback to run for any pkg dictionary. * @param[in] fn Function callback to run for any pkg dictionary.
* @param[in] arg Argument to be passed to the function callback. * @param[in] arg Argument to be passed to the function callback.
@ -789,12 +806,12 @@ int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
* @return 0 on success (all objects were processed), otherwise * @return 0 on success (all objects were processed), otherwise
* the value returned by the function callback. * the value returned by the function callback.
*/ */
int xbps_regpkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), int xbps_pkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
* Executes a function callback per a package dictionary registered * Executes a function callback per a package dictionary registered
* in "regpkgdb" plist, in reverse order (upwards). * in master package database (pkgdb) plist, in reverse order (upwards).
* *
* @param[in] fn Function callback to run for any pkg dictionary. * @param[in] fn Function callback to run for any pkg dictionary.
* @param[in] arg Argument to be passed to the function callback. * @param[in] arg Argument to be passed to the function callback.
@ -802,46 +819,68 @@ int xbps_regpkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
* @return 0 on success (all objects were processed), otherwise * @return 0 on success (all objects were processed), otherwise
* the value returned by the funcion callback. * the value returned by the funcion callback.
*/ */
int xbps_regpkgdb_foreach_reverse_pkg_cb( int xbps_pkgdb_foreach_reverse_pkg_cb(
int (*fn)(prop_object_t, void *, bool *), int (*fn)(prop_object_t, void *, bool *),
void *arg); void *arg);
/** /**
* Returns a package dictionary from regpkgdb plist, matching pkgname or * Returns a package dictionary from master package database (pkgdb) plist,
* pkgver specified in \a pkg. * matching pkgname or pkgver object in \a pkg.
* *
* @param[in] pkg Package name or name-version to match. * @param[in] pkg Package name or name-version to match.
* @param[in] bypattern If false \a pkg must be a pkgname, otherwise a * @param[in] bypattern If false \a pkg must be a pkgname, otherwise a
* package pattern, i.e `foo>=0' or `foo<1'. * package pattern, i.e `foo>=0' or `foo<1'.
* *
* @return The matching proplib package dictionary from regpkgdb copied * @return The matching proplib package dictionary from kgdb copied
* with \a prop_dictionary_copy() so it must be released when not required * with \a prop_dictionary_copy() so it must be released when not required
* anymore with prop_object_release(). NULL otherwise. * anymore with prop_object_release(). NULL otherwise.
*/ */
prop_dictionary_t xbps_regpkgdb_get_pkgd(const char *pkg, bool bypattern); prop_dictionary_t xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern);
/** /**
* Removes a package dictionary from regpkgdb plist matching the key * Removes a package dictionary from master package database (pkgdb) plist,
* \a pkgname. * matching pkgname or pkgver object in \a pkg.
* *
* @param[in] pkgname Package name to match in a dictionary. * @param[in] pkg Package name or pattern to match in a package dictionary.
* @param[in] bypattern If false \a pkg must be a pkgname, otherwise a
* package pattern, i.e `foo>=0' or `foo<1'.
* @param[in] flush If true, after successful replace the pkgdb contents
* in memory will be flushed atomically to storage.
* *
* @return true on success, false otherwise. * @return true on success, false otherwise.
*/ */
bool xbps_regpkgdb_remove_pkgd(const char *pkgname); bool xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush);
/** /**
* Updates the regpkgdb plist with new contents from disk to the cached copy * Replaces a package dictionary with \a dict in the master package database
* in memory. * (pkgdb) plist, matching pkgname or pkgver object.
*
* @param[in] dict Proplib dictionary to be added into pkgdb.
* @param[in] pkg Package name or pattern to match in a package dictionary.
* @param[in] bypattern If false \a pkg must be a pkgname, otherwise a
* package pattern, i.e `foo>=0' or `foo<1'.
* @param[in] flush If true, after successful replace the pkgdb contents in
* memory will be flushed atomically to storage.
*
* @return true on success, false otherwise.
*/
bool xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
const char *pkg,
bool bypattern,
bool flush);
/**
* Updates the master package database (pkgdb) plist with new contents from
* disk to the cached copy in memory.
* *
* @param[in] xhp Pointer to our xbps_handle struct, as returned by * @param[in] xhp Pointer to our xbps_handle struct, as returned by
* \a xbps_handle_get(). * \a xbps_handle_get().
* @param[in] flush If true the regpkgdb plist contents in memory will * @param[in] flush If true the pkgdb plist contents in memory will
* be flushed atomically to disk. * be flushed atomically to storage.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush); int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush);
/** /**
* Finds the proplib's dictionary associated with a package, by looking * Finds the proplib's dictionary associated with a package, by looking
@ -1133,6 +1172,18 @@ bool xbps_remove_pkg_dict_from_plist_by_name(const char *pkgname,
*/ */
bool xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name); bool xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name);
/**
* Removes the package's proplib dictionary matching the pkgver object
* with a package pattern from \a pattern in a proplib array.
*
* @param[in] array Proplib array where to look for.
* @param[in] pattern Package pattern to match, i.e `foo>=0' or `foo<1'.
*
* @return true on success, false otherwise and errno is set appropiately.
*/
bool xbps_remove_pkg_from_array_by_pattern(prop_array_t array,
const char *pattern);
/** /**
* Removes the package's proplib dictionary matching the \a pkgver * Removes the package's proplib dictionary matching the \a pkgver
* object in a proplib array of dictionaries. * object in a proplib array of dictionaries.
@ -1142,7 +1193,8 @@ bool xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name);
* *
* @return true on success, false otherwise and errno is set appropiately. * @return true on success, false otherwise and errno is set appropiately.
*/ */
bool xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, const char *pkgver); bool xbps_remove_pkg_from_array_by_pkgver(prop_array_t array,
const char *pkgver);
/** /**
* Removes the package's proplib dictionary matching \a pkgname, * Removes the package's proplib dictionary matching \a pkgname,
@ -1193,6 +1245,22 @@ int xbps_array_replace_dict_by_name(prop_array_t array,
prop_dictionary_t dict, prop_dictionary_t dict,
const char *pkgname); const char *pkgname);
/**
* Replaces a dictionary with another dictionary in \a dict, in
* the array \a array by matching its pkgver object with a package pattern,
* i.e `foo>=0' or `foo<1'.
*
* @param[in] array Proplib array where to look for.
* @param[in] dict Proplib dictionary to be added in \a array.
* @param[in] pattern Package pattern to be matched, i.e `foo>=0'.
*
* @return 0 on success, EINVAL id dictionary couldn't be set in the array
* or ENOENT if no match.
*/
int xbps_array_replace_dict_by_pattern(prop_array_t array,
prop_dictionary_t dict,
const char *pattern);
/*@}*/ /*@}*/
/** @addtogroup pkg_register */ /** @addtogroup pkg_register */
@ -1204,7 +1272,7 @@ int xbps_array_replace_dict_by_name(prop_array_t array,
* @param[in] pkg_dict A dictionary with the following objects: * @param[in] pkg_dict A dictionary with the following objects:
* \a pkgname, \a version, \a pkgver, \a short_desc (string), * \a pkgname, \a version, \a pkgver, \a short_desc (string),
* \a automatic-install (bool) and optionally \a provides (array of strings). * \a automatic-install (bool) and optionally \a provides (array of strings).
* @param[in] flush Set to true to make sure that regpkgdb plist * @param[in] flush Set to true to make sure that pkgdb plist
* is written to storage on success. * is written to storage on success.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
@ -1216,7 +1284,7 @@ int xbps_register_pkg(prop_dictionary_t pkg_dict, bool flush);
* *
* @param[in] pkgname Package name. * @param[in] pkgname Package name.
* @param[in] version Package version. * @param[in] version Package version.
* @param[in] flush Set to true to make sure that regpkgdb plist * @param[in] flush Set to true to make sure that pkgdb plist
* is written to storage on success. * is written to storage on success.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.

View File

@ -69,10 +69,10 @@ int HIDDEN dewey_match(const char *, const char *);
/** /**
* @private * @private
* From lib/regpkgdb_dictionary.c * From lib/pkgdb.c
*/ */
int HIDDEN xbps_regpkgdb_dictionary_init(struct xbps_handle *); int HIDDEN xbps_pkgdb_init(struct xbps_handle *);
void HIDDEN xbps_regpkgdb_dictionary_release(struct xbps_handle *); void HIDDEN xbps_pkgdb_release(struct xbps_handle *);
/** /**
* @private * @private

View File

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

View File

@ -65,9 +65,9 @@ xbps_configure_packages(bool flush)
struct xbps_handle *xhp = xbps_handle_get(); struct xbps_handle *xhp = xbps_handle_get();
int rv; 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) if (rv == 0 && flush)
rv = xbps_regpkgdb_update(xhp, true); rv = xbps_pkgdb_update(xhp, true);
return rv; return rv;
} }
@ -109,7 +109,7 @@ xbps_configure_pkg(const char *pkgname,
} else if (state != XBPS_PKG_STATE_UNPACKED) } else if (state != XBPS_PKG_STATE_UNPACKED)
return EINVAL; 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_dictionary_get_cstring_nocopy(pkgd, "version", &lver);
prop_object_release(pkgd); prop_object_release(pkgd);
} else { } else {
@ -169,7 +169,7 @@ xbps_configure_pkg(const char *pkgname,
} }
free(pkgver); free(pkgver);
if (flush) if (flush)
rv = xbps_regpkgdb_update(xhp, true); rv = xbps_pkgdb_update(xhp, true);
return rv; 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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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) if ((od.array = prop_array_create()) == NULL)
return NULL; return NULL;
/* /*
* Find out all orphans by looking at the * Find out all orphans by looking at pkgdb and iterating in reverse
* regpkgdb dictionary and iterate in reverse order * order in which packages were installed.
* in which packages were installed.
*/ */
od.orphans_user = orphans_user; 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) { if (rv != 0) {
errno = rv; errno = rv;
prop_object_release(od.array); prop_object_release(od.array);

View File

@ -43,7 +43,6 @@ int
xbps_register_pkg(prop_dictionary_t pkgrd, bool flush) xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
{ {
struct xbps_handle *xhp; struct xbps_handle *xhp;
prop_array_t array;
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
prop_array_t provides, reqby; prop_array_t provides, reqby;
const char *pkgname, *version, *desc, *pkgver; const char *pkgname, *version, *desc, *pkgver;
@ -69,7 +68,7 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
assert(desc != NULL); assert(desc != NULL);
assert(pkgver != NULL); assert(pkgver != NULL);
pkgd = xbps_regpkgdb_get_pkgd(pkgname, false); pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
if (pkgd == NULL) { if (pkgd == NULL) {
rv = ENOENT; rv = ENOENT;
goto out; goto out;
@ -127,16 +126,11 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
goto out; goto out;
} }
} }
array = prop_dictionary_get(xhp->regpkgdb, "packages"); if (!xbps_pkgdb_replace_pkgd(pkgd, pkgname, false, flush)) {
rv = xbps_array_replace_dict_by_name(array, pkgd, pkgname);
if (rv != 0) {
xbps_dbg_printf("%s: failed to replace pkgd dict for %s\n", xbps_dbg_printf("%s: failed to replace pkgd dict for %s\n",
__func__, pkgname); __func__, pkgname);
goto out; goto out;
} }
if (flush)
rv = xbps_regpkgdb_update(xhp, true);
out: out:
if (pkgd != NULL) if (pkgd != NULL)
prop_object_release(pkgd); prop_object_release(pkgd);
@ -154,23 +148,16 @@ out:
int int
xbps_unregister_pkg(const char *pkgname, const char *version, bool flush) xbps_unregister_pkg(const char *pkgname, const char *version, bool flush)
{ {
struct xbps_handle *xhp;
assert(pkgname != NULL); assert(pkgname != NULL);
xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, 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, xbps_set_cb_state(XBPS_STATE_UNREGISTER_FAIL,
errno, pkgname, version, errno, pkgname, version,
"%s: failed to unregister package: %s", "%s: failed to unregister package: %s",
pkgname, strerror(errno)); pkgname, strerror(errno));
return errno; return errno;
} }
if (flush) {
xhp = xbps_handle_get();
return xbps_regpkgdb_update(xhp, true);
}
return 0; 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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -413,7 +413,7 @@ purge:
goto out; goto out;
} }
/* /*
* Unregister package from regpkgdb. * Unregister package from pkgdb.
*/ */
if ((rv = xbps_unregister_pkg(pkgname, version, false)) != 0) if ((rv = xbps_unregister_pkg(pkgname, version, false)) != 0)
goto out; goto out;

View File

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

View File

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

View File

@ -136,10 +136,12 @@ extract_metafile(struct archive *ar,
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to extract metafile `%s': %s", "%s: [unpack] failed to extract metafile `%s': %s",
pkgver, file, strerror(rv)); pkgver, file, strerror(rv));
free(dirc);
free(pkgname); free(pkgname);
return rv; return rv;
} }
free(pkgname); free(pkgname);
free(dirc);
return 0; 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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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++) { for (i = 0; i < prop_array_count(array); i++) {
obj = prop_array_get(array, i); obj = prop_array_get(array, i);
if (obj == NULL)
continue;
rv = (*fn)(obj, arg, &cbloop_done); rv = (*fn)(obj, arg, &cbloop_done);
if (rv != 0 || cbloop_done) if (rv != 0 || cbloop_done)
break; break;
@ -130,6 +132,34 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
return rv; 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 int
xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
const char *key, const char *key,
@ -137,10 +167,6 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
void *arg) void *arg)
{ {
prop_array_t array; 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(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL); assert(key != NULL);
@ -152,17 +178,7 @@ xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
return EINVAL; return EINVAL;
} }
if ((cnt = prop_array_count(array)) == 0) return xbps_callback_array_iter_reverse(array, fn, arg);
return 0;
while (cnt--) {
obj = prop_array_get(array, cnt);
rv = (*fn)(obj, arg, &cbloop_done);
if (rv != 0 || cbloop_done)
break;
}
return rv;
} }
prop_object_iterator_t 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); return prop_array_iterator(array);
} }
int static int
xbps_array_replace_dict_by_name(prop_array_t array, array_replace_dict(prop_array_t array,
prop_dictionary_t dict, prop_dictionary_t dict,
const char *pkgname) const char *str,
bool bypattern)
{ {
prop_object_t obj; prop_object_t obj;
size_t i; 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(array) == PROP_TYPE_ARRAY);
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(pkgname != NULL); assert(str != NULL);
for (i = 0; i < prop_array_count(array); i++) { for (i = 0; i < prop_array_count(array); i++) {
obj = prop_array_get(array, i); obj = prop_array_get(array, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgname); if (obj == NULL)
if (strcmp(curpkgname, pkgname) == 0) { continue;
/* pkgname match, we know the index */ 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;
}
} else {
/* pkgname match */
prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &curpkgname);
if (strcmp(curpkgname, str) == 0) {
if (!prop_array_set(array, i, dict)) if (!prop_array_set(array, i, dict))
return EINVAL; return EINVAL;
return 0; return 0;
} }
} }
}
/* no match */ /* no match */
return ENOENT; 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 prop_dictionary_t
xbps_dictionary_from_metadata_plist(const char *pkgname, xbps_dictionary_from_metadata_plist(const char *pkgname,
const char *plist) const char *plist)

View File

@ -386,10 +386,10 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
assert(str != NULL); assert(str != NULL);
xhp = xbps_handle_get(); xhp = xbps_handle_get();
if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { if ((rv = xbps_pkgdb_init(xhp)) != 0) {
if (rv != ENOENT) { if (rv != ENOENT) {
xbps_dbg_printf("%s: couldn't initialize " xbps_dbg_printf("%s: couldn't initialize "
"regpkgdb: %s\n", strerror(rv)); "pkgdb: %s\n", strerror(rv));
return NULL; return NULL;
} else if (rv == ENOENT) } else if (rv == ENOENT)
return NULL; return NULL;
@ -397,16 +397,15 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
/* try normal pkg */ /* try normal pkg */
if (virtual == false) { if (virtual == false) {
pkgd = find_pkg_in_dict(xhp->regpkgdb, pkgd = find_pkg_in_array(xhp->pkgdb, str, bypattern, false);
"packages", str, bypattern, false);
} else { } else {
/* virtual pkg set by user in conf */ /* virtual pkg set by user in conf */
pkgd = find_virtualpkg_user_in_dict(xhp->regpkgdb, pkgd = find_virtualpkg_user_in_array(xhp->pkgdb,
"packages", str, bypattern); str, bypattern);
if (pkgd == NULL) { if (pkgd == NULL) {
/* any virtual pkg in dictionary matching pattern */ /* any virtual pkg in array matching pattern */
pkgd = find_pkg_in_dict(xhp->regpkgdb, pkgd = find_pkg_in_array(xhp->pkgdb,
"packages", str, bypattern, true); str, bypattern, true);
} }
} }
/* pkg not found */ /* 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. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,7 +40,7 @@
* all library functions. * all library functions.
*/ */
static bool 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_iterator_t iter;
prop_object_t obj; prop_object_t obj;
@ -90,6 +90,14 @@ remove_string_from_array(prop_array_t array, const char *str, int mode)
found = true; found = true;
break; 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++; idx++;
} }
@ -107,25 +115,31 @@ remove_string_from_array(prop_array_t array, const char *str, int mode)
bool bool
xbps_remove_string_from_array(prop_array_t array, const char *str) 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 bool
xbps_remove_pkgname_from_array(prop_array_t array, const char *name) 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 bool
xbps_remove_pkg_from_array_by_name(prop_array_t array, const char *name) 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 bool
xbps_remove_pkg_from_array_by_pkgver(prop_array_t array, const char *pkgver) 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 bool

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2008-2011 Juan Romero Pardines. * Copyright (c) 2008-2012 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -31,66 +31,41 @@
#include "xbps_api_impl.h" #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 int HIDDEN
xbps_regpkgdb_dictionary_init(struct xbps_handle *xhp) xbps_pkgdb_init(struct xbps_handle *xhp)
{ {
int rv; int rv;
assert(xhp != NULL); assert(xhp != NULL);
if (xhp->regpkgdb != NULL) if (xhp->pkgdb != NULL)
return 0; return 0;
rv = xbps_regpkgdb_update(xhp, false); rv = xbps_pkgdb_update(xhp, false);
if (rv != 0) { if (rv != 0) {
if (rv != ENOENT) if (rv != ENOENT)
xbps_dbg_printf("[regpkgdb] cannot internalize " xbps_dbg_printf("[pkgdb] cannot internalize "
"regpkgdb dictionary: %s\n", strerror(rv)); "pkgdb array: %s\n", strerror(rv));
return rv; return rv;
} }
xbps_dbg_printf("[regpkgdb] initialized ok.\n"); xbps_dbg_printf("[pkgdb] initialized ok.\n");
return 0; return 0;
} }
int int
xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush) xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
{ {
char *plist, *metadir; char *plist, *metadir;
int rv = 0; int rv = 0;
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir, plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_PKGDB);
if (plist == NULL) if (plist == NULL)
return ENOMEM; return ENOMEM;
if (xhp->regpkgdb != NULL && flush) { if (xhp->pkgdb != NULL && flush) {
metadir = xbps_xasprintf("%s/%s", xhp->rootdir, metadir = xbps_xasprintf("%s/%s", xhp->rootdir,
XBPS_META_PATH); XBPS_META_PATH);
if (metadir == NULL) { if (metadir == NULL) {
@ -101,7 +76,7 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush)
if (access(metadir, X_OK) == -1) { if (access(metadir, X_OK) == -1) {
if (errno == ENOENT) { if (errno == ENOENT) {
if (xbps_mkpath(metadir, 0755) != 0) { if (xbps_mkpath(metadir, 0755) != 0) {
xbps_dbg_printf("[regpkgdb] failed to " xbps_dbg_printf("[pkgdb] failed to "
"create metadir %s: %s\n", metadir, "create metadir %s: %s\n", metadir,
strerror(errno)); strerror(errno));
rv = errno; rv = errno;
@ -116,17 +91,16 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush)
} }
free(metadir); free(metadir);
/* flush dictionary to storage */ /* flush dictionary to storage */
if (!prop_dictionary_externalize_to_zfile(xhp->regpkgdb, if (!prop_array_externalize_to_zfile(xhp->pkgdb, plist)) {
plist)) {
free(plist); free(plist);
return errno; return errno;
} }
prop_object_release(xhp->regpkgdb); prop_object_release(xhp->pkgdb);
xhp->regpkgdb = NULL; xhp->pkgdb = NULL;
} }
/* update copy in memory */ /* update copy in memory */
xhp->regpkgdb = prop_dictionary_internalize_from_zfile(plist); xhp->pkgdb = prop_array_internalize_from_zfile(plist);
if (xhp->regpkgdb == NULL) if (xhp->pkgdb == NULL)
rv = errno; rv = errno;
free(plist); free(plist);
@ -135,16 +109,16 @@ xbps_regpkgdb_update(struct xbps_handle *xhp, bool flush)
} }
void HIDDEN void HIDDEN
xbps_regpkgdb_dictionary_release(struct xbps_handle *xhp) xbps_pkgdb_release(struct xbps_handle *xhp)
{ {
assert(xhp != NULL); assert(xhp != NULL);
if (xhp->regpkgdb == NULL) if (xhp->pkgdb == NULL)
return; return;
prop_object_release(xhp->regpkgdb); prop_object_release(xhp->pkgdb);
xhp->regpkgdb = NULL; xhp->pkgdb = NULL;
xbps_dbg_printf("[regpkgdb] released ok.\n"); xbps_dbg_printf("[pkgdb] released ok.\n");
} }
static int static int
@ -155,62 +129,96 @@ foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
struct xbps_handle *xhp = xbps_handle_get(); struct xbps_handle *xhp = xbps_handle_get();
int rv; int rv;
/* initialize regpkgdb */ if ((rv = xbps_pkgdb_init(xhp)) != 0)
if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0)
return rv; return rv;
if (reverse) { if (reverse)
rv = xbps_callback_array_iter_reverse_in_dict( rv = xbps_callback_array_iter_reverse(xhp->pkgdb, fn, arg);
xhp->regpkgdb, "packages", fn, arg); else
} else { rv = xbps_callback_array_iter(xhp->pkgdb, fn, arg);
rv = xbps_callback_array_iter_in_dict(
xhp->regpkgdb, "packages", fn, arg);
}
return rv; return rv;
} }
int int
xbps_regpkgdb_foreach_reverse_pkg_cb(int (*fn)(prop_object_t, void *, bool *), xbps_pkgdb_foreach_reverse_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
return foreach_pkg_cb(fn, arg, true); return foreach_pkg_cb(fn, arg, true);
} }
int int
xbps_regpkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *), xbps_pkgdb_foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
void *arg) void *arg)
{ {
return foreach_pkg_cb(fn, arg, false); return foreach_pkg_cb(fn, arg, false);
} }
prop_dictionary_t 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(); struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
if (xbps_regpkgdb_dictionary_init(xhp) != 0) if (xbps_pkgdb_init(xhp) != 0)
return NULL; return NULL;
if (bypattern) if (bypattern)
pkgd = xbps_find_pkg_in_dict_by_pattern(xhp->regpkgdb, pkgd = xbps_find_pkg_in_array_by_pattern(xhp->pkgdb, pkg);
"packages", pkg);
else else
pkgd = xbps_find_pkg_in_dict_by_name(xhp->regpkgdb, pkgd = xbps_find_pkg_in_array_by_name(xhp->pkgdb, pkg);
"packages", pkg);
if (pkgd != NULL)
return prop_dictionary_copy(pkgd); return prop_dictionary_copy(pkgd);
return NULL;
} }
bool 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(); 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 false;
return xbps_remove_pkg_from_dict_by_name(xhp->regpkgdb, if (bypattern)
"packages", pkgname); 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); uname(&un);
b = basename(p); b = basename(p);
if ((strcmp(b, "noarch")) && (strcmp(b, un.machine))) {
free(p); free(p);
if ((strcmp(b, "noarch")) && (strcmp(b, un.machine)))
return false; return false;
}
free(p);
return true; return true;
} }

View File

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

View File

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