From 4f50dad1470076e79bac4611b43526b20137d06a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 6 May 2012 21:42:15 -0500 Subject: [PATCH] pkg: provide error return codes for pkg_traverse() and pkg_verify_graph(). --- pkg.c | 34 +++++++++++++++++++++++----------- pkg.h | 4 ++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/pkg.c b/pkg.c index eb87a7e..fc14bfc 100644 --- a/pkg.c +++ b/pkg.c @@ -431,13 +431,13 @@ pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags, unsigned int * verify the graph dependency nodes are satisfiable by walking the tree using * pkg_traverse(). */ -void +unsigned int pkg_verify_graph(pkg_t *root, int depth, unsigned int flags) { - pkg_traverse(root, NULL, NULL, depth, flags); + return pkg_traverse(root, NULL, NULL, depth, flags); } -void +unsigned int pkg_report_graph_error(pkg_t *pkg, pkg_dependency_t *node, unsigned int eflags) { if (eflags & PKG_ERRF_PACKAGE_NOT_FOUND) @@ -460,17 +460,17 @@ pkg_report_graph_error(pkg_t *pkg, pkg_dependency_t *node, unsigned int eflags) if (pkg != NULL) pkg_free(pkg); - exit(EXIT_FAILURE); + return eflags; } -static inline void +static inline unsigned int pkg_walk_list(pkg_dependency_t *deplist, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int depth, unsigned int flags) { - unsigned int eflags; + unsigned int eflags = PKG_ERRF_OK; pkg_dependency_t *node; foreach_list_entry(deplist, node) @@ -488,6 +488,8 @@ pkg_walk_list(pkg_dependency_t *deplist, pkg_free(pkgdep); } + + return eflags; } /* @@ -495,21 +497,31 @@ pkg_walk_list(pkg_dependency_t *deplist, * * walk the dependency graph up to maxdepth levels. -1 means infinite recursion. */ -void +unsigned int pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth, unsigned int flags) { - if (maxdepth == 0) - return; + unsigned int eflags = PKG_ERRF_OK; - pkg_walk_list(root->requires, pkg_traverse_func, data, maxdepth, flags); + if (maxdepth == 0) + return eflags; + + eflags = pkg_walk_list(root->requires, pkg_traverse_func, data, maxdepth, flags); + if (eflags != PKG_ERRF_OK) + return eflags; if (flags & PKGF_SEARCH_PRIVATE) - pkg_walk_list(root->requires_private, pkg_traverse_func, data, maxdepth, flags); + { + eflags = pkg_walk_list(root->requires_private, pkg_traverse_func, data, maxdepth, flags); + if (eflags != PKG_ERRF_OK) + return eflags; + } if (pkg_traverse_func != NULL) pkg_traverse_func(root, data); + + return eflags; } diff --git a/pkg.h b/pkg.h index 4dc992e..d7b7e84 100644 --- a/pkg.h +++ b/pkg.h @@ -137,8 +137,8 @@ struct pkg_ { /* pkg.c */ void pkg_free(pkg_t *pkg); pkg_t *pkg_find(const char *name, unsigned int flags); -void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth, unsigned int flags); -void pkg_verify_graph(pkg_t *root, int depth, unsigned int flags); +unsigned int pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth, unsigned int flags); +unsigned int pkg_verify_graph(pkg_t *root, int depth, unsigned int flags); int pkg_compare_version(const char *a, const char *b); pkg_t *pkg_verify_dependency(pkg_dependency_t *pkgdep, unsigned int flags, unsigned int *eflags); const char *pkg_get_comparator(pkg_dependency_t *pkgdep);