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 <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Chantry Xavier 2008-01-22 01:28:05 +01:00 committed by Dan McGee
parent 927af790ee
commit b2914bf0af
8 changed files with 51 additions and 58 deletions

View file

@ -377,10 +377,10 @@ typedef enum _pmdepmod_t {
PM_DEP_MOD_LT
} pmdepmod_t;
pmdepend_t *alpm_splitdep(const char *depstring);
int alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep);
alpm_list_t *alpm_checkdeps(pmdb_t *db, int reversedeps,
alpm_list_t *remove, alpm_list_t *upgrade);
alpm_list_t *alpm_deptest(pmdb_t *db, alpm_list_t *targets);
const char *alpm_miss_get_target(const pmdepmissing_t *miss);
pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss);

View file

@ -458,7 +458,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
_alpm_strtrim(line);
if(strcmp(line, "%DEPENDS%") == 0) {
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
pmdepend_t *dep = alpm_splitdep(_alpm_strtrim(line));
pmdepend_t *dep = _alpm_splitdep(_alpm_strtrim(line));
info->depends = alpm_list_add(info->depends, dep);
}
} else if(strcmp(line, "%OPTDEPENDS%") == 0) {

View file

@ -93,7 +93,7 @@ static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
{
const char *pkg1name = alpm_pkg_get_name(pkg1);
const char *pkg2name = alpm_pkg_get_name(pkg2);
pmdepend_t *conf = alpm_splitdep(conflict);
pmdepend_t *conf = _alpm_splitdep(conflict);
int match = 0;
match = alpm_depcmp(pkg2, conf);

View file

@ -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;

View file

@ -56,7 +56,9 @@ void _alpm_depmiss_free(pmdepmissing_t *miss);
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode);
void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit);
int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
alpm_list_t **list, alpm_list_t *remove, pmtrans_t *trans, alpm_list_t **data);
alpm_list_t **list, alpm_list_t *remove, pmtrans_t *trans, alpm_list_t
**data);
pmdepend_t *_alpm_splitdep(const char *depstring);
#endif /* _ALPM_DEPS_H */

View file

@ -962,7 +962,7 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
/* size in the raw package is uncompressed (installed) size */
info->isize = atol(ptr);
} else if(!strcmp(key, "depend")) {
pmdepend_t *dep = alpm_splitdep(ptr);
pmdepend_t *dep = _alpm_splitdep(ptr);
info->depends = alpm_list_add(info->depends, dep);
} else if(!strcmp(key, "optdepend")) {
info->optdepends = alpm_list_add(info->optdepends, strdup(ptr));

View file

@ -1,20 +1,16 @@
self.description = "test deptest (-T) functionality"
sp1 = pmpkg("pkg1")
sp1.depends = ["dep"]
self.addpkg2db("sync", sp1)
lp1 = pmpkg("pkg1")
self.addpkg2db("local", lp1)
sp1dep = pmpkg("dep")
self.addpkg2db("sync", sp1dep)
lp3 = pmpkg("pkg3", "2.0-1")
lp3.provides = ("prov=3.0")
self.addpkg2db("local", lp3)
sp2 = pmpkg("pkg2")
self.addpkg2db("sync", sp2)
lp2 = pmpkg("pkg2")
self.addpkg2db("local", lp2)
self.args = "-T pkg1 pkg2"
self.args = "-T pkg1 pkg2 pkg3\>2.1 prov\>\=3.0"
self.addrule("PACMAN_RETCODE=127")
self.addrule("PACMAN_OUTPUT=pkg1")
self.addrule("!PACMAN_OUTPUT=pkg2")
self.addrule("!PACMAN_OUTPUT=pkg1")
self.addrule("PACMAN_OUTPUT=pkg2")
self.addrule("PACMAN_OUTPUT=pkg3")
self.addrule("!PACMAN_OUTPUT=prov")

View file

@ -31,53 +31,23 @@
#include "util.h"
#include "conf.h"
/* TODO: This should use _alpm_checkdeps() */
int pacman_deptest(alpm_list_t *targets)
{
int retval = 0;
alpm_list_t *i;
if(targets == NULL) {
alpm_list_t *deps = alpm_deptest(alpm_option_get_localdb(), targets);
if(deps == NULL) {
return(0);
}
for(i = targets; i; i = alpm_list_next(i)) {
int found = 0;
pmpkg_t *pkg;
pmdepend_t *dep;
const char *target;
alpm_list_t *j, *provides;
for(i = deps; i; i = alpm_list_next(i)) {
const char *dep;
target = alpm_list_getdata(i);
dep = alpm_splitdep(target);
pkg = alpm_db_get_pkg(alpm_option_get_localdb(),
alpm_dep_get_name(dep));
if(pkg && alpm_depcmp(pkg, dep)) {
found = 1;
} else {
/* not found, can we find anything that provides this in the local DB? */
provides = alpm_db_whatprovides(alpm_option_get_localdb(),
alpm_dep_get_name(dep));
for(j = provides; j; j = alpm_list_next(j)) {
pmpkg_t *pkg;
pkg = alpm_list_getdata(j);
if(pkg && alpm_depcmp(pkg, dep)) {
found = 1;
break;
dep = alpm_list_getdata(i);
printf("%s\n", dep);
}
}
alpm_list_free(provides);
}
if(!found) {
printf("%s\n", target);
retval = 127;
}
free(dep);
}
return(retval);
alpm_list_free(deps);
return(127);
}
/* vim: set ts=2 sw=2 noet: */