From: Michael Tremer Date: Mon, 25 Sep 2023 13:35:36 +0000 (+0000) Subject: build: Implement installing build dependencies using a transaction X-Git-Tag: 0.9.30~1657 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=83a751792e573f65ff95a137dcaec1cfd1e007b7;p=pakfire.git build: Implement installing build dependencies using a transaction Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 8385b8000..0b1439f6e 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -1665,36 +1665,53 @@ PAKFIRE_EXPORT int pakfire_build_set_target( return pakfire_string_set(build->target, target); } -static int pakfire_build_install_packages(struct pakfire_build* build, - int* snapshot_needs_update) { +static int pakfire_build_install_packages( + struct pakfire_build* build, int* snapshot_needs_update) { + struct pakfire_transaction* transaction = NULL; + char* problems = NULL; int r; - int changed = 0; + // Create a new transaction + r = pakfire_transaction_create(&transaction, build->pakfire, 0); + if (r) + goto ERROR; - // Install everything - r = pakfire_install(build->pakfire, 0, 0, PAKFIRE_BUILD_PACKAGES, NULL, 0, - &changed, NULL, NULL); - if (r) { - ERROR(build->pakfire, "Could not install build dependencies: %m\n"); - return r; + // Install all build dependencies + for (const char** p = PAKFIRE_BUILD_PACKAGES; *p; p++) { + r = pakfire_transaction_request(transaction, + PAKFIRE_JOB_INSTALL, *p, PAKFIRE_JOB_ESSENTIAL); + if (r) + goto ERROR; } - // Mark snapshot as changed if new packages were installed - if (changed) - *snapshot_needs_update = 1; + // Also update everything that has already been installed + r = pakfire_transaction_request(transaction, PAKFIRE_JOB_SYNC, NULL, 0); + if (r) + goto ERROR; - // Update everything - r = pakfire_sync(build->pakfire, 0, 0, &changed, NULL, NULL); + // Solve the transaction + r = pakfire_transaction_solve(transaction, 0, &problems); if (r) { - ERROR(build->pakfire, "Could not update packages: %m\n"); - return r; + ERROR(build->pakfire, "Could not install build dependencies:\n%s\n", problems); + goto ERROR; } - // Has anything changed? - if (changed) + // If there are changes, we have to update the snapshot + if (pakfire_transaction_count(transaction)) *snapshot_needs_update = 1; - return 0; + // 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; } /*