From: Michael Tremer Date: Tue, 9 Feb 2021 18:12:28 +0000 (+0000) Subject: pakfire: Tidy up initialisation X-Git-Tag: 0.9.28~1285^2~777 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f1dca7e037121ea907e6f49118e225cfb7ed15b;p=pakfire.git pakfire: Tidy up initialisation The code that sets up the pool has now entirely moved into a separate function. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 39db934c8..1d0d5f08a 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -86,6 +86,17 @@ static int pakfire_populate_pool(Pakfire pakfire) { struct pakfire_db* db; int r; + // Initialize the pool + Pool* pool = pakfire->pool = pool_create(); + pool_setdisttype(pool, DISTTYPE_RPM); + +#ifdef SOLVER_DEBUG + pool_setdebuglevel(pool, 1); +#endif + + // Set architecture of the pool + pool_setarch(pool, pakfire->arch); + // Open database in read-only mode and try to load all installed packages r = pakfire_db_open(&db, pakfire, PAKFIRE_DB_READWRITE); if (r) @@ -173,28 +184,13 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char private_dir, strerror(errno)); free(private_dir); - pakfire_free(p); - return r; + goto ERROR; } - // Initialize the pool - p->pool = pool_create(); - pool_setdisttype(p->pool, DISTTYPE_RPM); - -#ifdef SOLVER_DEBUG - pool_setdebuglevel(p->pool, 1); -#endif - - // Set architecture of the pool - pool_setarch(p->pool, p->arch); - // Populate pool r = pakfire_populate_pool(p); - if (r) { - pakfire_free(p); - - return r; - } + if (r) + goto ERROR; // Initialise cache pakfire_set_cache_path(p, CACHE_PATH); @@ -202,6 +198,11 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char *pakfire = p; return 0; + +ERROR: + pakfire_free(p); + + return r; } PAKFIRE_EXPORT Pakfire pakfire_ref(Pakfire pakfire) {