]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Tidy up initialisation
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Feb 2021 18:12:28 +0000 (18:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 9 Feb 2021 18:12:28 +0000 (18:12 +0000)
The code that sets up the pool has now entirely moved into a separate
function.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 39db934c8e424ee0c529c6d42c090078ed636655..1d0d5f08a1bdeebf5022d514dbba6c855cc8e45a 100644 (file)
@@ -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) {