]> git.ipfire.org Git - pakfire.git/commitdiff
build: Implement a simple function to install packages in a shell
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 Sep 2023 13:43:16 +0000 (13:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 Sep 2023 13:43:16 +0000 (13:43 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 0b1439f6eee6c684bd57a701844ba950fb9c7e31..aeb7ede74b8fd341b2355bad34c65b686cd4391a 100644 (file)
@@ -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