pkg: add pkg_queue_validate() to compile and validate a pkg_queue_t.

William Pitcock 2012-07-29 05:36:21 -05:00
parent 7719a32491
commit 74f6f7b858
3 changed files with 42 additions and 4 deletions

6
main.c
View File

@ -687,6 +687,12 @@ main(int argc, char *argv[])
ret = EXIT_SUCCESS;
if (!pkg_queue_validate(pkgq_head, maximum_traverse_depth, global_traverse_flags))
{
ret = EXIT_FAILURE;
goto out;
}
if (want_uninstalled)
{
ret = EXIT_FAILURE;

2
pkg.h
View File

@ -118,6 +118,7 @@ struct pkg_ {
#define PKG_ERRF_PACKAGE_NOT_FOUND 0x1
#define PKG_ERRF_PACKAGE_VER_MISMATCH 0x2
#define PKG_ERRF_PACKAGE_CONFLICT 0x4
#define PKG_ERRF_DEPGRAPH_BREAK 0x8
typedef void (*pkg_iteration_func_t)(const pkg_t *pkg);
typedef void (*pkg_traverse_func_t)(pkg_t *pkg, void *data, unsigned int flags);
@ -177,5 +178,6 @@ pkg_queue_t *pkg_queue_push(pkg_queue_t *parent, const char *package);
bool pkg_queue_compile(pkg_t *world, pkg_queue_t *head);
void pkg_queue_free(pkg_queue_t *head);
bool pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data);
bool pkg_queue_validate(pkg_queue_t *head, int maxdepth, unsigned int flags);
#endif

38
queue.c
View File

@ -60,6 +60,15 @@ pkg_queue_free(pkg_queue_t *head)
}
}
static inline unsigned int
pkg_queue_verify(pkg_t *world, pkg_queue_t *head, int maxdepth, unsigned int flags)
{
if (!pkg_queue_compile(world, head))
return PKG_ERRF_DEPGRAPH_BREAK;
return pkg_verify_graph(world, maxdepth, flags);
}
bool
pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data)
{
@ -69,16 +78,13 @@ pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, un
.flags = PKG_PROPF_VIRTUAL,
};
if (!pkg_queue_compile(&world, head))
return false;
/* if maxdepth is one, then we will not traverse deeper than our virtual package. */
if (!maxdepth)
maxdepth = -1;
else if (maxdepth > 0)
maxdepth++;
if (pkg_verify_graph(&world, maxdepth, flags) != PKG_ERRF_OK)
if (pkg_queue_verify(&world, head, maxdepth, flags) != PKG_ERRF_OK)
return false;
func(&world, data, maxdepth, flags);
@ -87,3 +93,27 @@ pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, un
return true;
}
bool
pkg_queue_validate(pkg_queue_t *head, int maxdepth, unsigned int flags)
{
bool retval = true;
pkg_t world = {
.id = "world",
.realname = "virtual world package",
.flags = PKG_PROPF_VIRTUAL,
};
/* if maxdepth is one, then we will not traverse deeper than our virtual package. */
if (!maxdepth)
maxdepth = -1;
else if (maxdepth > 0)
maxdepth++;
if (pkg_queue_verify(&world, head, maxdepth, flags) != PKG_ERRF_OK)
retval = false;
pkg_free(&world);
return retval;
}