]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Add stub mode
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 4 Feb 2025 18:06:20 +0000 (18:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 4 Feb 2025 18:06:20 +0000 (18:06 +0000)
This should be used in the build service or other situations where we
only need dependency solving.

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

index fb21cea4182af1cdf4d620c3961ff987b191af76..7ef5f3edaad7954e2687c3bb77ca318d9c291a70 100644 (file)
@@ -261,6 +261,10 @@ static int pakfire_setup_path(struct pakfire* self, const char* path) {
        // Template when running Pakfire in a temporary environment
        char tmppath[PATH_MAX] = PAKFIRE_TMP_DIR "/pakfire-root-XXXXXX";
 
+       // Don't do any of this when in stub mode
+       if (pakfire_has_flag(self, PAKFIRE_FLAGS_STUB))
+               return 0;
+
        // If we don't have a path, create something temporary...
        if (!path) {
                // Create a new temporary directory
@@ -983,6 +987,13 @@ int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
 
        // Check path
        if (path) {
+               // Check that we don't have a path in stub mode
+               if (flags & PAKFIRE_FLAGS_STUB) {
+                       ERROR(ctx, "Cannot use path in stub mode\n");
+                       r = -EINVAL;
+                       goto ERROR;
+               }
+
                // Check that we don't have path set when using snapshots
                if (flags & PAKFIRE_USE_SNAPSHOT) {
                        ERROR(ctx, "Cannot use path with snapshots\n");
@@ -1095,18 +1106,21 @@ int pakfire_create(struct pakfire** pakfire, struct pakfire_ctx* ctx,
        if (r < 0)
                goto ERROR;
 
-       // Setup the local repository
-       if (p->flags & (PAKFIRE_FLAGS_BUILD|PAKFIRE_FLAGS_BUILD_LOCAL)) {
-               r = pakfire_setup_local_repo(p);
-               if (r < 0)
-                       goto ERROR;
-       }
+       // Skip a couple of steps when in stub mode
+       if (!pakfire_has_flag(p, PAKFIRE_FLAGS_STUB)) {
+               // Setup the local repository
+               if (p->flags & (PAKFIRE_FLAGS_BUILD|PAKFIRE_FLAGS_BUILD_LOCAL)) {
+                       r = pakfire_setup_local_repo(p);
+                       if (r < 0)
+                               goto ERROR;
+               }
 
-       // Read repository configuration
-       if (p->internal_flags & PAKFIRE_HAS_PATH) {
-               r = pakfire_read_repo_config(p);
-               if (r < 0)
-                       goto ERROR;
+               // Read repository configuration
+               if (p->internal_flags & PAKFIRE_HAS_PATH) {
+                       r = pakfire_read_repo_config(p);
+                       if (r < 0)
+                               goto ERROR;
+               }
        }
 
        // Load installed packages
index a253e75e0b7e0d69afced1658970c05323ee4a63..557393c9cb5cf351f585d0a9c33d489fa205227c 100644 (file)
@@ -46,9 +46,10 @@ struct pakfire;
 #include <pakfire/transaction.h>
 
 enum pakfire_flags {
-       PAKFIRE_FLAGS_BUILD             = (1 << 0),
-       PAKFIRE_FLAGS_BUILD_LOCAL       = (1 << 1),
-       PAKFIRE_USE_SNAPSHOT            = (1 << 2),
+       PAKFIRE_FLAGS_STUB              = (1 << 0),
+       PAKFIRE_FLAGS_BUILD             = (1 << 1),
+       PAKFIRE_FLAGS_BUILD_LOCAL       = (1 << 2),
+       PAKFIRE_USE_SNAPSHOT            = (1 << 3),
 };
 
 // Callbacks
index 8b9a7be64edc29dc7d5de65a8af8c48d92db38b4..dbdccb413ab5f5451a07096dae8fbb73a030634e 100644 (file)
@@ -34,6 +34,25 @@ FAIL:
        return EXIT_FAILURE;
 }
 
+static int test_stub(const struct test* t) {
+       struct pakfire* pakfire = NULL;
+       int r = EXIT_FAILURE;
+
+       // Have some illegal calls
+       ASSERT_ERROR(pakfire_create(&pakfire, t->ctx, t->config, "PATH", NULL, PAKFIRE_FLAGS_STUB), EINVAL);
+
+       // Have a success call
+       ASSERT_SUCCESS(pakfire_create(&pakfire, t->ctx, t->config, NULL, NULL, PAKFIRE_FLAGS_STUB));
+
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (pakfire)
+               pakfire_unref(pakfire);
+
+       return r;
+}
+
 static int test_fail(const struct test* t) {
        struct pakfire_config* config = NULL;
        struct pakfire* pakfire = NULL;
@@ -66,6 +85,7 @@ FAIL:
 
 int main(int argc, const char* argv[]) {
        testsuite_add_test(test_init, TEST_WANTS_PAKFIRE);
+       testsuite_add_test(test_stub, 0);
        testsuite_add_test(test_fail, 0);
 
        return testsuite_run(argc, argv);