diff --git a/main.c b/main.c index c55a711..8e69e9a 100644 --- a/main.c +++ b/main.c @@ -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; diff --git a/pkg.h b/pkg.h index 5806114..8c32dba 100644 --- a/pkg.h +++ b/pkg.h @@ -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 diff --git a/queue.c b/queue.c index fb6a874..e56aa73 100644 --- a/queue.c +++ b/queue.c @@ -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; +}