]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
pakfire_whatprovides/requires: Write to an existant list
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Feb 2023 15:00:46 +0000 (15:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 28 Feb 2023 15:00:46 +0000 (15:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c

index 40d97bcd43263a17260c956bd944171a993c5625..114197bdfd332ab4d0bcc5292c5b43cae2118e57 100644 (file)
@@ -701,39 +701,65 @@ static PyObject* Pakfire_fetch_key(PakfireObject* self, PyObject* args, PyObject
 static PyObject* Pakfire_whatprovides(PakfireObject* self, PyObject* args) {
        const char* provides = NULL;
        struct pakfire_packagelist* list = NULL;
+       PyObject* ret = NULL;
+       int r;
 
        if (!PyArg_ParseTuple(args, "s", &provides))
                return NULL;
 
-       int r = pakfire_whatprovides(self->pakfire, provides, 0, &list);
+       // Create a new 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_whatprovides(self->pakfire, provides, 0, list);
+       if (r) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               goto ERROR;
+       }
 
-       return obj;
+       // Create a Python list from the package list
+       ret = PyList_FromPackageList(list);
+
+ERROR:
+       if (list)
+               pakfire_packagelist_unref(list);
+
+       return ret;
 }
 
 static PyObject* Pakfire_whatrequires(PakfireObject* self, PyObject* args) {
        const char* requires = NULL;
        struct pakfire_packagelist* list = NULL;
+       PyObject* ret = NULL;
+       int r;
 
        if (!PyArg_ParseTuple(args, "s", &requires))
                return NULL;
 
-       int r = pakfire_whatrequires(self->pakfire, requires, 0, &list);
+       // Create a new 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_whatprovides(self->pakfire, requires, 0, list);
+       if (r) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               goto ERROR;
+       }
 
-       return obj;
+       // Create a Python list from the package list
+       ret = PyList_FromPackageList(list);
+
+ERROR:
+       if (list)
+               pakfire_packagelist_unref(list);
+
+       return ret;
 }
 
 static PyObject* Pakfire_search(PakfireObject* self, PyObject* args, PyObject* kwds) {
index 36de4efe53b0becaf9608dc785dbdc12fc28ca1f..54693ae09171673ee7c4e03a4f8185675513718f 100644 (file)
@@ -77,9 +77,9 @@ struct pakfire_repolist* pakfire_get_repos(struct pakfire* pakfire);
 struct pakfire_repo* pakfire_get_repo(struct pakfire* pakfire, const char* name);
 
 int pakfire_whatprovides(struct pakfire* pakfire, const char* what, int flags,
-       struct pakfire_packagelist** list);
+       struct pakfire_packagelist* list);
 int pakfire_whatrequires(struct pakfire* pakfire, const char* what, int flags,
-       struct pakfire_packagelist** list);
+       struct pakfire_packagelist* list);
 
 // Search
 
index 318cf5d69194e8912942849d4c3c64c0f8d24fbd..59d99e33e641f24f0584ec3648dbf78c479e75d3 100644 (file)
@@ -1447,7 +1447,7 @@ ERROR:
 }
 
 static int pakfire_search_dep(struct pakfire* pakfire, Id type, const char* what, int flags,
-               struct pakfire_packagelist** list) {
+               struct pakfire_packagelist* list) {
        int r;
 
        // Get the pool ready
@@ -1460,23 +1460,17 @@ static int pakfire_search_dep(struct pakfire* pakfire, Id type, const char* what
                return 1;
        }
 
-       // Reset pointer
-       *list = NULL;
-
        Queue matches;
        queue_init(&matches);
 
        // Search for anything that matches
        pool_whatmatchesdep(pakfire->pool, type, dep, &matches, 0);
 
-       // Create a packagelist
-       r = pakfire_packagelist_create_from_queue(list, pakfire, &matches);
+       // Add the result to the packagelist
+       r = pakfire_packagelist_import_solvables(list, &matches);
        if (r)
                goto ERROR;
 
-       // Sort the list
-       pakfire_packagelist_sort(*list);
-
 ERROR:
        queue_free(&matches);
 
@@ -1484,12 +1478,12 @@ ERROR:
 }
 
 PAKFIRE_EXPORT int pakfire_whatprovides(struct pakfire* pakfire, const char* what, int flags,
-               struct pakfire_packagelist** list) {
+               struct pakfire_packagelist* list) {
        return pakfire_search_dep(pakfire, SOLVABLE_PROVIDES, what, flags, list);
 }
 
 PAKFIRE_EXPORT int pakfire_whatrequires(struct pakfire* pakfire, const char* what, int flags,
-               struct pakfire_packagelist** list) {
+               struct pakfire_packagelist* list) {
        return pakfire_search_dep(pakfire, SOLVABLE_REQUIRES, what, flags, list);
 }