Exemple #1
0
alpm_list_t *list_add_unique(alpm_list_t *list, void *data)
{
	if(alpm_list_find_ptr(list, data)) {
		return list; 
	} else {
		return alpm_list_add(list, data);
	}
}
Exemple #2
0
/**
 * @brief Create a new list without any duplicates.
 *
 * This does NOT copy data members.
 *
 * @param list the list to copy
 *
 * @return a new list containing non-duplicate items
 */
alpm_list_t SYMEXPORT *alpm_list_remove_dupes(const alpm_list_t *list)
{
	const alpm_list_t *lp = list;
	alpm_list_t *newlist = NULL;
	while(lp) {
		if(!alpm_list_find_ptr(newlist, lp->data)) {
			newlist = alpm_list_add(newlist, lp->data);
		}
		lp = lp->next;
	}
	return newlist;
}
Exemple #3
0
void add_deps(alpm_pkg_t *pkg)
{
	alpm_list_t *i;
	for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
		char *depstring = alpm_dep_compute_string(i->data);
		alpm_pkg_t *p = alpm_find_satisfier(pkgcache, depstring);
		if(p && !alpm_list_find_ptr(packages, p)) {
			packages = alpm_list_add(packages, p);
			add_deps(p);
		}
		free(depstring);
	}
	if(checks & CHECK_OPT_DEPENDS) {
		for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) {
			char *depstring = alpm_dep_compute_string(i->data);
			alpm_pkg_t *p = alpm_find_satisfier(pkgcache, depstring);
			if(p && !alpm_list_find_ptr(packages, p)) {
				packages = alpm_list_add(packages, p);
				add_deps(p);
			}
			free(depstring);
		}
	}
}
Exemple #4
0
int target_arg_add (target_arg_t *t, const char *s, void *item)
{
	int ret=1;
	if (t && config.just_one)
	{
		if ((t->cmp_fn && alpm_list_find (t->items, item, t->cmp_fn)) ||
		    (!t->cmp_fn && alpm_list_find_ptr (t->items, item)))
			ret = 0;
		else if (t->dup_fn)
			t->items = alpm_list_add (t->items, t->dup_fn (item));
		else
			t->items = alpm_list_add (t->items, item);
		t->args = alpm_list_add (t->args, (void *) s);
	}
	return ret;
}
Exemple #5
0
bool target_arg_add (target_arg_t *t, const char *s, void *item)
{
	bool ret = true;
	if (t && config.just_one) {
		if ((t->cmp_fn && alpm_list_find (t->items, item, t->cmp_fn)) ||
				(!t->cmp_fn && alpm_list_find_ptr (t->items, item))) {
			ret = false;
		} else if (t->dup_fn) {
			t->items = alpm_list_add (t->items, t->dup_fn (item));
		} else {
			t->items = alpm_list_add (t->items, item);
		}
		t->args = alpm_list_add (t->args, (void *) s);
	}
	return ret;
}
/**
 * pacman_list_find_direct:
 * @haystack: A #PacmanList.
 * @needle: An item to find.
 *
 * Searches @haystack for an item that points to the same location as @needle.
 *
 * Returns: A list item from @haystack, or %NULL if none were found.
 */
gpointer pacman_list_find_direct (const PacmanList *haystack, gconstpointer needle) {
	return alpm_list_find_ptr (haystack, needle);
}
Exemple #7
0
/* Re-order a list of target packages with respect to their dependencies.
 *
 * Example (reverse == 0):
 *   A depends on C
 *   B depends on A
 *   Target order is A,B,C,D
 *
 *   Should be re-ordered to C,A,B,D
 *
 * packages listed in ignore will not be used to detect indirect dependencies
 *
 * if reverse is > 0, the dependency order will be reversed.
 *
 * This function returns the new alpm_list_t* target list.
 *
 */
alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle,
		alpm_list_t *targets, alpm_list_t *ignore, int reverse)
{
	alpm_list_t *newtargs = NULL;
	alpm_list_t *vertices = NULL;
	alpm_list_t *vptr;
	alpm_graph_t *vertex;

	if(targets == NULL) {
		return NULL;
	}

	_alpm_log(handle, ALPM_LOG_DEBUG, "started sorting dependencies\n");

	vertices = dep_graph_init(handle, targets, ignore);

	vptr = vertices;
	vertex = vertices->data;
	while(vptr) {
		/* mark that we touched the vertex */
		vertex->state = -1;
		int found = 0;
		while(vertex->childptr && !found) {
			alpm_graph_t *nextchild = vertex->childptr->data;
			vertex->childptr = vertex->childptr->next;
			if(nextchild->state == 0) {
				found = 1;
				nextchild->parent = vertex;
				vertex = nextchild;
			} else if(nextchild->state == -1) {
				/* child is an ancestor of vertex */
				alpm_graph_t *transvertex = vertex;

				if(!alpm_list_find_ptr(targets, nextchild->data)) {
					/* child is not part of the transaction, not a problem */
					continue;
				}

				/* find the nearest parent that's part of the transaction */
				while(transvertex) {
					if(alpm_list_find_ptr(targets, transvertex->data)) {
						break;
					}
					transvertex = transvertex->parent;
				}

				if(!transvertex || transvertex == nextchild) {
					/* no transaction package in our ancestry or the package has
					 * a circular dependency with itself, not a problem */
				} else {
					alpm_pkg_t *transpkg = transvertex->data;
					alpm_pkg_t *childpkg = nextchild->data;
					_alpm_log(handle, ALPM_LOG_WARNING, _("dependency cycle detected:\n"));
					if(reverse) {
						_alpm_log(handle, ALPM_LOG_WARNING,
								_("%s will be removed after its %s dependency\n"),
								transpkg->name, childpkg->name);
					} else {
						_alpm_log(handle, ALPM_LOG_WARNING,
								_("%s will be installed before its %s dependency\n"),
								transpkg->name, childpkg->name);
					}
				}
			}
		}
		if(!found) {
			if(alpm_list_find_ptr(targets, vertex->data)) {
				newtargs = alpm_list_add(newtargs, vertex->data);
			}
			/* mark that we've left this vertex */
			vertex->state = 1;
			vertex = vertex->parent;
			if(!vertex) {
				/* top level vertex reached, move to the next unprocessed vertex */
				for( vptr = vptr->next; vptr; vptr = vptr->next) {
					vertex = vptr->data;
					if(vertex->state == 0) {
						break;
					}
				}
			}
		}
	}

	_alpm_log(handle, ALPM_LOG_DEBUG, "sorting dependencies finished\n");

	if(reverse) {
		/* reverse the order */
		alpm_list_t *tmptargs = alpm_list_reverse(newtargs);
		/* free the old one */
		alpm_list_free(newtargs);
		newtargs = tmptargs;
	}

	alpm_list_free_inner(vertices, _alpm_graph_free);
	alpm_list_free(vertices);

	return newtargs;
}