From: Michael Tremer Date: Thu, 30 Jan 2025 20:50:05 +0000 (+0000) Subject: packagelist: Add helper function to check if a certain path is on the list X-Git-Tag: 0.9.30~240 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=26c228444167a6596f5ebfef41c46011ebdb3d7c;p=pakfire.git packagelist: Add helper function to check if a certain path is on the list Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/packagelist.c b/src/pakfire/packagelist.c index 2bbc7e95..5c1614ca 100644 --- a/src/pakfire/packagelist.c +++ b/src/pakfire/packagelist.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include struct pakfire_packagelist { struct pakfire_ctx* ctx; @@ -206,3 +208,19 @@ int pakfire_packagelist_import_solvables(struct pakfire_packagelist* self, return 0; } + +static int __pakfire_packagelist_has_path( + struct pakfire_ctx* ctx, struct pakfire_package* pkg, void* data) { + const char* path = data; + + // Fetch the path where we would expect this package to be + const char* pkg_path = pakfire_package_get_path(pkg); + if (unlikely(!pkg_path)) + return -EINVAL; + + return pakfire_string_equals(pkg_path, path); +} + +int pakfire_packagelist_has_path(struct pakfire_packagelist* self, const char* path) { + return pakfire_packagelist_walk(self, __pakfire_packagelist_has_path, (char*)path, 0); +} diff --git a/src/pakfire/packagelist.h b/src/pakfire/packagelist.h index d8e2f677..962cb565 100644 --- a/src/pakfire/packagelist.h +++ b/src/pakfire/packagelist.h @@ -51,4 +51,6 @@ int pakfire_packagelist_walk(struct pakfire_packagelist* list, int pakfire_packagelist_import_solvables(struct pakfire_packagelist* list, struct pakfire* pakfire, Queue* q); +int pakfire_packagelist_has_path(struct pakfire_packagelist* self, const char* path); + #endif /* PAKFIRE_PACKAGELIST_H */