From b2914bf0af388f369865859292b1c7342e785303 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Tue, 22 Jan 2008 01:28:05 +0100 Subject: Move the deptest code from frontend to backend. The deptest code (pacman -T) used by makepkg was mostly in the frontend. There were 2 drawbacks: 1) the public splitdep function returns a pmdepend_t struct, but the _alpm_dep_free function for freeing it is private. So there was a memleak. 2) there is a helper in the backend (satisfycmp in deps.c) which makes this function much easier. So this adds a new public alpm_deptest in libalpm/deps.c, which cleans pacman_deptest in pacman/deptest.c a lot. Besides, alpm_splitdep was made private, because the frontend no longer requires it, and _alpm_dep_free is also private. Finally the deptest001 pactest was extended. Signed-off-by: Chantry Xavier Signed-off-by: Dan McGee --- lib/libalpm/deps.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/deps.c') diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 12da6b09..163b22ba 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -223,6 +223,31 @@ static int satisfycmp(const void *pkg, const void *depend) return(!alpm_depcmp((pmpkg_t*) pkg, (pmdepend_t*) depend)); } +/** Checks dependencies and returns missing ones in a list. + * Dependencies can include versions with depmod operators. + * @param db pointer to the local package database + * @param targets an alpm_list_t* of dependencies strings to satisfy + * @return an alpm_list_t* of missing dependencies strings + */ +alpm_list_t SYMEXPORT *alpm_deptest(pmdb_t *db, alpm_list_t *targets) +{ + alpm_list_t *i, *ret = NULL; + + for(i = targets; i; i = alpm_list_next(i)) { + pmdepend_t *dep; + char *target; + + target = alpm_list_getdata(i); + dep = _alpm_splitdep(target); + + if(!alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp)) { + ret = alpm_list_add(ret, target); + } + _alpm_dep_free(dep); + } + return(ret); +} + /** Checks dependencies and returns missing ones in a list. * Dependencies can include versions with depmod operators. * @param db pointer to the local package database @@ -364,7 +389,7 @@ int SYMEXPORT alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep) return(satisfy); } -pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring) +pmdepend_t *_alpm_splitdep(const char *depstring) { pmdepend_t *depend; char *ptr = NULL; -- cgit v1.2.3-24-g4f1b