From 6d4cbcd3390dcaecb8e1a2e507ee7cafc97b126e Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 25 Sep 2023 13:43:16 +0000 Subject: [PATCH] build: Implement a simple function to install packages in a shell Signed-off-by: Michael Tremer --- src/libpakfire/build.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 0b1439f6e..aeb7ede74 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -2418,6 +2418,44 @@ ERROR: return r; } +static int pakfire_build_install(struct pakfire_build* build, const char** packages) { + struct pakfire_transaction* transaction = NULL; + char* problems = NULL; + int r; + + // Create a new transaction + r = pakfire_transaction_create(&transaction, build->pakfire, 0); + if (r) + goto ERROR; + + // Install all packages + for (const char** p = packages; *p; p++) { + r = pakfire_transaction_request(transaction, PAKFIRE_JOB_INSTALL, *p, 0); + if (r) + goto ERROR; + } + + // Solve the transaction + r = pakfire_transaction_solve(transaction, 0, &problems); + if (r) { + ERROR(build->pakfire, "Could not install packages:\n%s\n", problems); + goto ERROR; + } + + // Run the transaction + r = pakfire_transaction_run(transaction); + if (r) + goto ERROR; + +ERROR: + if (transaction) + pakfire_transaction_unref(transaction); + if (problems) + free(problems); + + return r; +} + /* This is a convenience function that sets up a build environment and then drops the user into an interactive shell. @@ -2443,9 +2481,9 @@ PAKFIRE_EXPORT int pakfire_shell(struct pakfire* pakfire, const char** packages, // Install any additional packages if (packages) { - r = pakfire_install(build->pakfire, 0, 0, packages, NULL, 0, NULL, NULL, NULL); + r = pakfire_build_install(build, packages); if (r) - return r; + goto ERROR; } // Run shell -- 2.47.2