const char* pattern = NULL;
int name_only = 0;
int flags = 0;
+ PyObject* ret = NULL;
+ int r;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|$p", kwlist, &pattern, &name_only))
return NULL;
if (name_only)
flags |= PAKFIRE_SEARCH_NAME_ONLY;
- int r = pakfire_search(self->pakfire, pattern, flags, &list);
+ r = pakfire_packagelist_create(&list, self->pakfire);
if (r) {
PyErr_SetFromErrno(PyExc_OSError);
- return NULL;
+ goto ERROR;
}
- PyObject* obj = PyList_FromPackageList(list);
- pakfire_packagelist_unref(list);
+ r = pakfire_search(self->pakfire, pattern, flags, list);
+ if (r) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ goto ERROR;
+ }
- return obj;
+ ret = PyList_FromPackageList(list);
+
+ERROR:
+ if (list)
+ pakfire_packagelist_unref(list);
+
+ return ret;
}
static PyObject* Pakfire_version_compare(PakfireObject* self, PyObject* args) {
return r;
}
+static int __pakfire_search(struct pakfire* pakfire, struct pakfire_packagelist* list,
+ const Id* keys, const char* what, int flags) {
+ Dataiterator di;
+ Queue matches;
+ int r;
+
+ // Get the pool ready
+ pakfire_pool_internalize(pakfire);
+
+ // Initialize the result queue
+ queue_init(&matches);
+
+ // Setup the data interator
+ dataiterator_init(&di, pakfire->pool, 0, 0, 0, what, flags);
+
+ // Search through these keys and add matches to the queue
+ for (const 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);
+ }
+
+ // Import matches into the package list
+ r = pakfire_packagelist_import_solvables(list, &matches);
+ if (r)
+ goto ERROR;
+
+ERROR:
+ dataiterator_free(&di);
+ queue_free(&matches);
+
+ return r;
+}
+
+static int pakfire_search_filelist(struct pakfire* pakfire, const char* what, int flags,
+ struct pakfire_packagelist* list) {
+ const Id keys[] = {
+ SOLVABLE_FILELIST,
+ ID_NULL,
+ };
+
+ return __pakfire_search(pakfire, list, keys, what, SEARCH_FILES|SEARCH_GLOB);
+}
+
static int pakfire_search_dep(struct pakfire* pakfire, Id type, const char* what, int flags,
struct pakfire_packagelist* list) {
int r;
PAKFIRE_EXPORT int pakfire_whatprovides(struct pakfire* pakfire, const char* what, int flags,
struct pakfire_packagelist* list) {
- return pakfire_search_dep(pakfire, SOLVABLE_PROVIDES, what, flags, list);
+ int r;
+
+ // Check for valid input
+ if (!what || !list) {
+ errno = EINVAL;
+ return 1;
+ }
+
+ // Search for all packages that match this dependency
+ r = pakfire_search_dep(pakfire, SOLVABLE_PROVIDES, what, flags, list);
+ if (r)
+ return r;
+
+ // Search the filelist
+ if (*what == '/') {
+ r = pakfire_search_filelist(pakfire, what, flags, list);
+ if (r)
+ return r;
+ }
+
+ return 0;
}
PAKFIRE_EXPORT int pakfire_whatrequires(struct pakfire* pakfire, const char* what, int flags,
}
PAKFIRE_EXPORT int pakfire_search(struct pakfire* pakfire, const char* what, int flags,
- struct pakfire_packagelist** list) {
- Queue matches;
- Dataiterator di;
- int r;
-
- // Get the pool ready
- pakfire_pool_internalize(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);
-
+ struct pakfire_packagelist* list) {
const Id keys[] = {
SOLVABLE_NAME,
SOLVABLE_SUMMARY,
ID_NULL
};
- // Search through these keys and add matches to the queue
- for (const 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);
-
- // Stop after name
- if (flags & PAKFIRE_SEARCH_NAME_ONLY)
- break;
- }
-
- // 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);
+ const Id keys_name_only[] = {
+ SOLVABLE_NAME,
+ ID_NULL
+ };
- return r;
+ return __pakfire_search(pakfire,
+ list,
+ (flags & PAKFIRE_SEARCH_NAME_ONLY) ? keys_name_only : keys,
+ what,
+ SEARCH_SUBSTRING|SEARCH_NOCASE);
}
// Logging