summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2008-01-22 01:28:05 +0100
committerDan McGee <dan@archlinux.org>2008-01-21 19:35:43 -0600
commitb2914bf0af388f369865859292b1c7342e785303 (patch)
treee0433b54d7a9d7e0bc07bed1830e940bfc663c9c /lib/libalpm
parent927af790ee3ff1495acd2c6b33378a7ab20e0c67 (diff)
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>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm.h2
-rw-r--r--lib/libalpm/be_files.c2
-rw-r--r--lib/libalpm/conflict.c2
-rw-r--r--lib/libalpm/deps.c27
-rw-r--r--lib/libalpm/deps.h4
-rw-r--r--lib/libalpm/package.c2
6 files changed, 33 insertions, 6 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 4797fcfa..49580c0e 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -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);
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index f95c87a4..d3ec89a4 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -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) {
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 0fad4e4a..f666d595 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -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);
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
@@ -226,6 +226,31 @@ static int satisfycmp(const void *pkg, const void *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
* @param reversedeps handles the backward dependencies
* @param remove an alpm_list_t* of packages to be removed
* @param upgrade an alpm_list_t* of packages to be upgraded (remove-then-upgrade)
@@ -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;
diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
index debd5347..fdbfebed 100644
--- a/lib/libalpm/deps.h
+++ b/lib/libalpm/deps.h
@@ -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 */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 40667038..2bcf7453 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -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));