]> git.ipfire.org Git - pakfire.git/commitdiff
build: Implement installing build dependencies using a transaction
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 Sep 2023 13:35:36 +0000 (13:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 Sep 2023 13:35:36 +0000 (13:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 8385b80005ef0b0bac5c334b9bdd5f8280dadbbf..0b1439f6eee6c684bd57a701844ba950fb9c7e31 100644 (file)
@@ -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;
 }
 
 /*