]> git.ipfire.org Git - people/ric9/pakfire.git/commitdiff
pakfire: Always require a configuration
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 17:50:32 +0000 (17:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 11 Jan 2025 17:55:18 +0000 (17:55 +0000)
It is pretty pointless to run Pakfire without configuration and so we
can keep the code a bit more tidy.

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

index 76f442d8bde8d6f4b11619cba7806d2c9d84256e..7b30b6ffa9746027d3ed4c787c18e476b39600d1 100644 (file)
@@ -806,6 +806,10 @@ int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
        struct pakfire* p = NULL;
        int r;
 
+       // Always require a configuration
+       if (!config)
+               return -EINVAL;
+
        // Default to the native architecture
        if (!arch)
                arch = pakfire_arch_native();
@@ -842,13 +846,7 @@ int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
        p->flags = flags;
 
        // Store a reference to the configuration
-       if (config) {
-               p->config = pakfire_config_ref(config);
-       } else {
-               r = pakfire_config_create(&p->config);
-               if (r < 0)
-                       goto ERROR;
-       }
+       p->config = pakfire_config_ref(config);
 
        // Store the nominal architecture
        r = pakfire_string_set(p->arches.nominal, arch);
index f5b9c4fd47568d352798ca88ecaa36fd23c570f7..8b9a7be64edc29dc7d5de65a8af8c48d92db38b4 100644 (file)
@@ -35,25 +35,33 @@ FAIL:
 }
 
 static int test_fail(const struct test* t) {
+       struct pakfire_config* config = NULL;
        struct pakfire* pakfire = NULL;
+       int r = EXIT_FAILURE;
+
+       // Create a configuration
+       ASSERT_SUCCESS(pakfire_config_create(&config));
 
        // Init without anything
-       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, NULL, NULL, 0) == -EINVAL);
+       ASSERT_ERROR(pakfire_create(&pakfire, t->ctx, NULL, NULL, NULL, 0), EINVAL);
 
        // Invalid architecture
-       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, NULL, "arch", 0) == -ENOTSUP);
+       ASSERT_ERROR(pakfire_create(&pakfire, t->ctx, config, NULL, "arch", 0), ENOTSUP);
 
        // Invalid path (must be absolute)
-       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, "path", NULL, 0) == -EINVAL);
+       ASSERT_ERROR(pakfire_create(&pakfire, t->ctx, config, "path", NULL, 0), EINVAL);
 
        // Cannot use snapshots with a path
-       ASSERT(pakfire_create(&pakfire, t->ctx, NULL, PAKFIRE_TMP_DIR "/test",
-               NULL, PAKFIRE_USE_SNAPSHOT) == -EINVAL);
+       ASSERT_ERROR(pakfire_create(&pakfire, t->ctx, NULL, PAKFIRE_TMP_DIR "/test",
+               NULL, PAKFIRE_USE_SNAPSHOT)EINVAL);
 
-       return EXIT_SUCCESS;
+       r = EXIT_SUCCESS;
 
 FAIL:
-       return EXIT_FAILURE;
+       if (config)
+               pakfire_config_unref(config);
+
+       return r;
 }
 
 int main(int argc, const char* argv[]) {