From f8fd122c1538712e1847c9613c16a4f5a8e017b1 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 4 Feb 2025 18:06:20 +0000 Subject: [PATCH] pakfire: Add stub mode This should be used in the build service or other situations where we only need dependency solving. Signed-off-by: Michael Tremer --- src/pakfire/pakfire.c | 36 +++++++++++++++++++++++++----------- src/pakfire/pakfire.h | 7 ++++--- tests/libpakfire/main.c | 20 ++++++++++++++++++++ 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/pakfire/pakfire.c b/src/pakfire/pakfire.c index fb21cea41..7ef5f3eda 100644 --- a/src/pakfire/pakfire.c +++ b/src/pakfire/pakfire.c @@ -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 diff --git a/src/pakfire/pakfire.h b/src/pakfire/pakfire.h index a253e75e0..557393c9c 100644 --- a/src/pakfire/pakfire.h +++ b/src/pakfire/pakfire.h @@ -46,9 +46,10 @@ struct pakfire; #include 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 diff --git a/tests/libpakfire/main.c b/tests/libpakfire/main.c index 8b9a7be64..dbdccb413 100644 --- a/tests/libpakfire/main.c +++ b/tests/libpakfire/main.c @@ -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); -- 2.39.5