diff options
author | Xavier Chantry <shiningxc@gmail.com> | 2008-07-24 12:26:09 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-07-25 05:16:29 +0200 |
commit | b8e306b73e9b22fae3e45e5f5a3e8c07b63904b9 (patch) | |
tree | 9fd1cc526c60f9d209101b2d9759305f64ae5b46 | |
parent | 8877c88defdd9ea90bed9fb569addfa2b242a0f4 (diff) | |
download | pacman-b8e306b73e9b22fae3e45e5f5a3e8c07b63904b9.tar.gz pacman-b8e306b73e9b22fae3e45e5f5a3e8c07b63904b9.tar.xz |
Implement AND based package searching.
This fixes FS#2334.
Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
[Dan: add some comments to the code]
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | lib/libalpm/db.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 0be81cb1..83db429d 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -357,6 +357,8 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles) { const alpm_list_t *i, *j, *k; alpm_list_t *ret = NULL; + /* copy the pkgcache- we will free the list var after each needle */ + alpm_list_t *list = alpm_list_copy(_alpm_db_get_pkgcache(db)); ALPM_LOG_FUNC; @@ -367,6 +369,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles) if(i->data == NULL) { continue; } + ret = NULL; targ = i->data; _alpm_log(PM_LOG_DEBUG, "searching for target '%s'\n", targ); @@ -374,7 +377,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles) RET_ERR(PM_ERR_INVALID_REGEX, NULL); } - for(j = _alpm_db_get_pkgcache(db); j; j = j->next) { + for(j = list; j; j = j->next) { pmpkg_t *pkg = j->data; const char *matched = NULL; const char *name = alpm_pkg_get_name(pkg); @@ -407,6 +410,10 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles) } } + /* Free the existing search list, and use the returned list for the + * next needle. This allows for AND-based package searching. */ + alpm_list_free(list); + list = ret; regfree(®); } |