From 3ebd125e1ad9abbf5fbcb4457adb8288750b379e Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Thu, 1 Mar 2007 07:03:05 +0000 Subject: * Switched some functions to alpm_pkg_get_* usage as I came across them * Added some provision switching hackery. This could probably use some refactoring,.. it solves the following case: pkg1 and pkg2 provide 'foo' and are both installed pkg3 depends on 'foo' and so lists 'pkg1' in the REQUIREDBY db section pkg1 is upgraded and no longer provides 'foo' ** This code ensures that the REQUIREDBY of pkg3 is updated to require pkg2 now instead of pkg1 --- lib/libalpm/alpm_list.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/libalpm/alpm_list.c') diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index e118a129..8c387eed 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -457,6 +457,33 @@ int alpm_list_find_str(alpm_list_t *haystack, const char *needle) return(0); } +/** + * Calculate the items in list `lhs` that are not present in list `rhs` + * @note Entries are not duplicated + * @param lhs the first list + * @param rhs the second list + * @param fn the comparisson function + * @return a list containing all items in lhs not present in rhs + */ +alpm_list_t *alpm_list_diff(alpm_list_t *lhs, alpm_list_t *rhs, alpm_list_fn_cmp fn) +{ + alpm_list_t *i, *j, *ret = NULL; + for(i = lhs; i; i = i->next) { + int found = 0; + for(j = rhs; j; j = j->next) { + if(fn(i->data, j->data) == 0) { + found = 1; + break; + } + } + if(!found) { + ret = alpm_list_add(ret, i->data); + } + } + + return(ret); +} + /** @} */ /* vim: set ts=2 sw=2 noet: */ -- cgit v1.2.3-54-g00ecf