From: Michael Tremer Date: Thu, 29 Apr 2021 21:10:25 +0000 (+0000) Subject: pakfire: Add a custom namespace for features X-Git-Tag: 0.9.28~1285^2~189 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2025988119e863a702a6297d00de88fa8f438cf;p=pakfire.git pakfire: Add a custom namespace for features Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 5427f787a..2a394fb1b 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -95,6 +95,16 @@ struct _Pakfire { } distro; }; +/* + This is a list of all features that are supported by this version of Pakfire +*/ +static const struct pakfire_feature { + const char* name; +} features[] = { + { "Compress-Zstandard" }, + { NULL }, +}; + static const struct pakfire_mountpoint { const char* source; const char* target; @@ -328,6 +338,28 @@ static void pool_log(Pool* pool, void* data, int type, const char* s) { DEBUG(pakfire, "pool: %s", s); } +static Id pakfire_namespace_callback(Pool* pool, void* data, Id ns, Id id) { + Pakfire pakfire = (Pakfire)data; + + const char* namespace = pool_id2str(pool, ns); + const char* name = pool_dep2str(pool, id); + + DEBUG(pakfire, "Namespace callback called for %s(%s)\n", namespace, name); + + // We only handle the pakfire namesapce + if (strcmp(namespace, "pakfire") != 0) + return 0; + + // Find all supported features + for (const struct pakfire_feature* feature = features; feature->name; feature++) { + if (strcmp(feature->name, name) == 0) + return 1; + } + + // Not supported + return 0; +} + static int pakfire_populate_pool(Pakfire pakfire) { struct pakfire_db* db; PakfireRepo repo = NULL; @@ -352,6 +384,9 @@ static int pakfire_populate_pool(Pakfire pakfire) { // Set debug callback pool_setdebugcallback(pool, pool_log, pakfire); + // Install namespace callback + pool_setnamespacecallback(pool, pakfire_namespace_callback, pakfire); + // Open database in read-only mode and try to load all installed packages r = pakfire_db_open(&db, pakfire, PAKFIRE_DB_READWRITE); if (r)