From: Michael Tremer Date: Wed, 30 Jun 2021 15:43:05 +0000 (+0000) Subject: package: Add function that returns all packages that depend on this one X-Git-Tag: 0.9.28~1150 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1d77c573dc7059e22701e16ae34b55082255da5;p=pakfire.git package: Add function that returns all packages that depend on this one Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index adb4746c0..d3ea4bef4 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -29,6 +29,7 @@ #include "package.h" #include "pakfire.h" #include "repo.h" +#include "util.h" PyObject* new_package(PyTypeObject* type, PakfirePackage pkg) { PackageObject* self = (PackageObject *)type->tp_alloc(type, 0); @@ -507,6 +508,21 @@ static PyObject* Package_get_suggests(PackageObject* self) { return list; } +static PyObject* Package_get_reverse_requires(PackageObject* self) { + struct pakfire_packagelist* list = NULL; + + int r = pakfire_package_get_reverse_requires(self->package, &list); + if (r) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + + PyObject* object = PyList_FromPackageList(list); + pakfire_packagelist_unref(list); + + return object; +} + static PyObject* Package_get_filelist(PackageObject* self, PyObject* args) { PyObject* list = PyList_New(0); if (list == NULL) @@ -822,6 +838,13 @@ static struct PyGetSetDef Package_getsetters[] = { NULL, NULL }, + { + "reverse_requires", + (getter)Package_get_reverse_requires, + NULL, + NULL, + NULL + }, // Repository { diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 36304a2a5..8eaf12d3a 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -24,6 +24,7 @@ #include #include +#include #include PakfirePackage pakfire_package_create(Pakfire pakfire, PakfireRepo repo, @@ -92,6 +93,9 @@ char** pakfire_package_get_suggests(PakfirePackage pkg); char** pakfire_package_get_supplements(PakfirePackage pkg); char** pakfire_package_get_enhances(PakfirePackage pkg); +int pakfire_package_get_reverse_requires(PakfirePackage pkg, + struct pakfire_packagelist** list); + PakfireRepo pakfire_package_get_repo(PakfirePackage pkg); char* pakfire_package_dump(PakfirePackage pkg, int flags); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 9b1e426ac..75b9d17ec 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -166,6 +166,7 @@ global: pakfire_package_get_recommends; pakfire_package_get_repo; pakfire_package_get_requires; + pakfire_package_get_reverse_requires; pakfire_package_get_size; pakfire_package_get_suggests; pakfire_package_get_summary; diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 30071f87b..9a59731ce 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -734,6 +734,30 @@ void pakfire_package_add_enhances(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_ENHANCES, dep, 0); } +PAKFIRE_EXPORT int pakfire_package_get_reverse_requires(PakfirePackage pkg, + struct pakfire_packagelist** list) { + Queue matches; + queue_init(&matches); + + // Reset pointer + *list = NULL; + + Pool* pool = pakfire_get_solv_pool(pkg->pakfire); + + // Search for any matches + pool_whatmatchessolvable(pool, SOLVABLE_REQUIRES, pkg->id, &matches, 0); + + // Create a new package list + int r = pakfire_packagelist_create_from_queue(list, pkg->pakfire, &matches); + if (r) + goto ERROR; + +ERROR: + queue_free(&matches); + + return r; +} + PAKFIRE_EXPORT PakfireRepo pakfire_package_get_repo(PakfirePackage pkg) { if (!pkg->repo) { Solvable* s = get_solvable(pkg);