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 <string.h>
#include <errno.h>
#include <assert.h>
#include <unistd.h>
#include <sys/param.h>
@@ -38,6 +37,7 @@
struct checkpkg {
size_t npkgs;
size_t nbrokenpkgs;
bool flush;
};
static int
@@ -45,15 +45,17 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
{
struct checkpkg *cpkg = arg;
const char *pkgname, *version;
bool flush = false;
(void)done;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &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->flush = flush;
cpkg->npkgs++;
return 0;
}
@@ -61,26 +63,33 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
int
check_pkg_integrity_all(void)
{
struct checkpkg *cpkg;
cpkg = calloc(1, sizeof(*cpkg));
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);
struct xbps_handle *xhp = xbps_handle_get();
struct checkpkg cpkg;
int rv;
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;
}
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;
int rv = 0;
bool broken = false;
bool pkgdb_update = false, broken = false;
propsd = filesd = opkgd = NULL;
@@ -101,7 +110,7 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname)
* Check for props.plist metadata file.
*/
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 "
"file.\n", pkgname, XBPS_PKGPROPS);
broken = true;
@@ -116,7 +125,7 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname)
* Check for files.plist metadata file.
*/
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 "
"file.\n", pkgname, XBPS_PKGFILES);
broken = true;
@@ -128,9 +137,9 @@ check_pkg_integrity(prop_dictionary_t pkgd, const char *pkgname)
goto out;
}
#define RUN_PKG_CHECK(name, arg) \
#define RUN_PKG_CHECK(name, arg, arg2) \
do { \
rv = check_pkg_##name(pkgname, arg); \
rv = check_pkg_##name(pkgname, arg, arg2); \
if (rv) \
broken = true; \
else if (rv == -1) { \
@@ -141,11 +150,20 @@ do { \
} while (0)
/* Execute pkg checks */
RUN_PKG_CHECK(requiredby, pkgd ? pkgd : opkgd);
RUN_PKG_CHECK(autoinstall, pkgd ? pkgd : opkgd);
RUN_PKG_CHECK(files, filesd);
RUN_PKG_CHECK(symlinks, filesd);
RUN_PKG_CHECK(rundeps, propsd);
RUN_PKG_CHECK(requiredby, pkgd ? pkgd : opkgd, &pkgdb_update);
RUN_PKG_CHECK(autoinstall, pkgd ? pkgd : opkgd, &pkgdb_update);
RUN_PKG_CHECK(files, filesd, &pkgdb_update);
RUN_PKG_CHECK(symlinks, filesd, &pkgdb_update);
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