From 17fc01b4e0ce4344b41de58687f2f102a3e7d023 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 29 Jul 2012 04:45:21 -0500 Subject: [PATCH] queue: add pkg_queue_apply(). --- pkg.h | 2 ++ queue.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pkg.h b/pkg.h index c3f55fe..5806114 100644 --- a/pkg.h +++ b/pkg.h @@ -121,6 +121,7 @@ struct pkg_ { typedef void (*pkg_iteration_func_t)(const pkg_t *pkg); typedef void (*pkg_traverse_func_t)(pkg_t *pkg, void *data, unsigned int flags); +typedef void (*pkg_queue_apply_func_t)(pkg_t *world, void *data, int maxdepth, unsigned int flags); /* pkg.c */ void pkg_free(pkg_t *pkg); @@ -175,5 +176,6 @@ extern FILE *error_msgout; 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); #endif diff --git a/queue.c b/queue.c index 3d1d7d6..fb6a874 100644 --- a/queue.c +++ b/queue.c @@ -59,3 +59,31 @@ pkg_queue_free(pkg_queue_t *head) free(pkgq); } } + +bool +pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data) +{ + pkg_t world = { + .id = "world", + .realname = "virtual world package", + .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) + return false; + + func(&world, data, maxdepth, flags); + + pkg_free(&world); + + return true; +}