}
static PyObject* Pakfire_search(PakfireObject* self, PyObject* args) {
- const char* what;
+ struct pakfire_packagelist* list = NULL;
+ const char* what = NULL;
if (!PyArg_ParseTuple(args, "s", &what))
return NULL;
- struct pakfire_packagelist* list = pakfire_search(self->pakfire, what, 0);
+ int r = pakfire_search(self->pakfire, what, 0, &list);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
PyObject* obj = PyList_FromPackageList(list);
pakfire_packagelist_unref(list);
return pakfire_repo_create_from_repo(pakfire, pakfire->pool->installed);
}
-static struct pakfire_packagelist* pakfire_pool_dataiterator(Pakfire pakfire, const char* what, int key, int flags) {
- struct pakfire_packagelist* list = NULL;
-
- int r = pakfire_packagelist_create(&list, pakfire);
- if (r)
- return NULL;
-
- pakfire_pool_apply_changes(pakfire);
-
- int di_flags = 0;
- if (flags & PAKFIRE_SUBSTRING)
- di_flags |= SEARCH_SUBSTRING;
- else
- di_flags |= SEARCH_STRING;
-
- if (flags & PAKFIRE_ICASE)
- di_flags |= SEARCH_NOCASE;
- if (flags & PAKFIRE_GLOB)
- di_flags |= SEARCH_GLOB;
-
- Dataiterator di;
- dataiterator_init(&di, pakfire->pool, 0, 0, key, what, di_flags);
- while (dataiterator_step(&di)) {
- struct pakfire_package* pkg = pakfire_package_create_from_solvable(pakfire, di.solvid);
- pakfire_packagelist_push_if_not_exists(list, pkg);
- }
- dataiterator_free(&di);
-
- return list;
-}
-
static int pakfire_search_dep(Pakfire pakfire, Id type, const char* what, int flags,
struct pakfire_packagelist** list) {
// Refresh repositories
return pakfire_search_dep(pakfire, SOLVABLE_REQUIRES, what, flags, list);
}
-PAKFIRE_EXPORT struct pakfire_packagelist* pakfire_search(Pakfire pakfire, const char* what, int flags) {
+PAKFIRE_EXPORT int pakfire_search(Pakfire pakfire, const char* what, int flags,
+ struct pakfire_packagelist** list) {
+ Queue matches;
+ Dataiterator di;
+
// Refresh repositories
int r = pakfire_refresh(pakfire, 0);
if (r)
- return NULL;
+ return r;
- return pakfire_pool_dataiterator(pakfire, what, 0, PAKFIRE_SUBSTRING);
+ // Get the pool ready
+ pakfire_pool_apply_changes(pakfire);
+
+ // Initialize the result queue
+ queue_init(&matches);
+
+ // Setup the data interator
+ dataiterator_init(&di, pakfire->pool, 0, 0, 0, what, SEARCH_SUBSTRING|SEARCH_NOCASE);
+
+ Id keys[] = {
+ SOLVABLE_NAME,
+ SOLVABLE_SUMMARY,
+ SOLVABLE_DESCRIPTION,
+ ID_NULL
+ };
+
+ // Search through these keys and add matches to the queue
+ for (Id* key = keys; *key; key++) {
+ dataiterator_set_keyname(&di, *key);
+ dataiterator_set_search(&di, 0, 0);
+
+ while (dataiterator_step(&di))
+ queue_pushunique(&matches, di.solvid);
+ }
+
+ // Convert matches to package list
+ r = pakfire_packagelist_create_from_queue(list, pakfire, &matches);
+ if (r)
+ goto ERROR;
+
+ // Sort the result
+ pakfire_packagelist_sort(*list);
+
+ERROR:
+ dataiterator_free(&di);
+ queue_free(&matches);
+
+ return r;
}
// Cache