From: Michael Tremer Date: Fri, 7 Feb 2025 23:05:04 +0000 (+0000) Subject: pakfire: Add a simple function to install packages X-Git-Tag: 0.9.30~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6b5afa1cbb9c68cdaa76e912feffdd53153bb888;p=pakfire.git pakfire: Add a simple function to install packages This will come handy when generating images. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/pakfire.c b/src/pakfire/pakfire.c index fdbc65c2..08a17ccb 100644 --- a/src/pakfire/pakfire.c +++ b/src/pakfire/pakfire.c @@ -1926,3 +1926,46 @@ ERROR: return r; } + +/* + * Convenience function to install a couple of packages. Simple. + */ +int pakfire_install(struct pakfire* self, const char** packages) { + struct pakfire_transaction* transaction = NULL; + char* problems = NULL; + int r; + + // Create a new transaction + r = pakfire_transaction_create(&transaction, self, 0); + if (r < 0) + goto ERROR; + + // Install all packages + for (const char** package = packages; *package; package++) { + r = pakfire_transaction_request(transaction, PAKFIRE_JOB_INSTALL, *package, 0); + if (r < 0) + goto ERROR; + } + + // Solve the transaction + r = pakfire_transaction_solve(transaction, 0, &problems); + if (r) { + if (problems) + ERROR(self->ctx, "Could not install packages:\n%s\n", problems); + + goto ERROR; + } + + // Run the transaction + r = pakfire_transaction_run(transaction); + if (r < 0) + goto ERROR; + +ERROR: + if (transaction) + pakfire_transaction_unref(transaction); + if (problems) + free(problems); + + return r; +} diff --git a/src/pakfire/pakfire.h b/src/pakfire/pakfire.h index b23ab4b6..c15f54f8 100644 --- a/src/pakfire/pakfire.h +++ b/src/pakfire/pakfire.h @@ -155,4 +155,6 @@ int pakfire_repo_walk(struct pakfire* pakfire, struct archive* pakfire_get_disk_reader(struct pakfire* pakfire); struct archive* pakfire_get_disk_writer(struct pakfire* pakfire); +int pakfire_install(struct pakfire* self, const char** packages); + #endif /* PAKFIRE_PAKFIRE_H */