2012-07-29 08:49:56 +00:00
|
|
|
/*
|
|
|
|
* queue.c
|
|
|
|
* compilation of a list of packages into a world dependency set
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 pkgconf authors (see AUTHORS).
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pkg.h"
|
|
|
|
#include "bsdstubs.h"
|
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
typedef struct {
|
|
|
|
pkg_node_t iter;
|
|
|
|
char *package;
|
|
|
|
} pkg_queue_t;
|
|
|
|
|
|
|
|
void
|
|
|
|
pkg_queue_push(pkg_list_t *list, const char *package)
|
2012-07-29 08:49:56 +00:00
|
|
|
{
|
|
|
|
pkg_queue_t *pkgq = calloc(sizeof(pkg_queue_t), 1);
|
|
|
|
|
|
|
|
pkgq->package = strdup(package);
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_node_insert_tail(&pkgq->iter, pkgq, list);
|
2012-07-29 08:49:56 +00:00
|
|
|
}
|
2012-07-29 08:56:20 +00:00
|
|
|
|
|
|
|
bool
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_queue_compile(pkg_t *world, pkg_list_t *list)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_node_t *iter;
|
2012-07-29 08:56:20 +00:00
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
PKG_FOREACH_LIST_ENTRY(list->head, iter)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_queue_t *pkgq;
|
2012-07-29 08:56:20 +00:00
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
pkgq = iter->data;
|
2013-03-01 17:36:21 +00:00
|
|
|
pkg_dependency_parse(world, &world->requires, pkgq->package);
|
2012-07-29 08:56:20 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
return (world->requires.head != NULL);
|
2012-07-29 08:56:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_queue_free(pkg_list_t *list)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_node_t *node, *tnode;
|
2012-07-29 08:56:20 +00:00
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
PKG_FOREACH_LIST_ENTRY_SAFE(list->head, tnode, node)
|
2012-07-29 08:56:20 +00:00
|
|
|
{
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_queue_t *pkgq = node->data;
|
|
|
|
|
2012-07-29 08:56:20 +00:00
|
|
|
free(pkgq->package);
|
|
|
|
free(pkgq);
|
|
|
|
}
|
|
|
|
}
|
2012-07-29 09:45:21 +00:00
|
|
|
|
2012-07-29 10:36:21 +00:00
|
|
|
static inline unsigned int
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_queue_verify(pkg_t *world, pkg_list_t *list, int maxdepth, unsigned int flags)
|
2012-07-29 10:36:21 +00:00
|
|
|
{
|
2013-03-01 16:24:57 +00:00
|
|
|
if (!pkg_queue_compile(world, list))
|
2012-07-29 10:36:21 +00:00
|
|
|
return PKG_ERRF_DEPGRAPH_BREAK;
|
|
|
|
|
|
|
|
return pkg_verify_graph(world, maxdepth, flags);
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:45:21 +00:00
|
|
|
bool
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_queue_apply(pkg_list_t *list, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data)
|
2012-07-29 09:45:21 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
if (pkg_queue_verify(&world, list, maxdepth, flags) != PKG_ERRF_OK)
|
2012-07-29 09:45:21 +00:00
|
|
|
return false;
|
|
|
|
|
2012-08-12 10:32:31 +00:00
|
|
|
if (!func(&world, data, maxdepth, flags))
|
|
|
|
{
|
|
|
|
pkg_free(&world);
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-29 09:45:21 +00:00
|
|
|
|
|
|
|
pkg_free(&world);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-29 10:36:21 +00:00
|
|
|
|
|
|
|
bool
|
2013-03-01 16:24:57 +00:00
|
|
|
pkg_queue_validate(pkg_list_t *list, int maxdepth, unsigned int flags)
|
2012-07-29 10:36:21 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2013-03-01 16:24:57 +00:00
|
|
|
if (pkg_queue_verify(&world, list, maxdepth, flags) != PKG_ERRF_OK)
|
2012-07-29 10:36:21 +00:00
|
|
|
retval = false;
|
|
|
|
|
|
|
|
pkg_free(&world);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|