]> git.ipfire.org Git - pakfire.git/commitdiff
transaction: Avoid using a label to retry solving
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 27 Oct 2024 08:59:47 +0000 (08:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 27 Oct 2024 11:37:55 +0000 (11:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/transaction.c

index c28b3671bd8762f6e7e3497bb60c24181bac71f0..fe2d3ffb3291859347f1e798745ee15192fa09a7 100644 (file)
@@ -574,73 +574,75 @@ PAKFIRE_EXPORT int pakfire_transaction_solve(struct pakfire_transaction* transac
        if (selection)
                DEBUG(transaction->ctx, "Solving: %s\n", selection);
 
-RETRY:
-       // Save time when we starting solving
-       solving_start = clock();
+       for (;;) {
+               // Save time when we starting solving
+               solving_start = clock();
 
-       // Solve the request and get the number of problems
-       r = solver_solve(transaction->solver, &transaction->jobs);
+               // Solve the request and get the number of problems
+               r = solver_solve(transaction->solver, &transaction->jobs);
 
-       // Save time when we finished solving
-       solving_end = clock();
+               // Save time when we finished solving
+               solving_end = clock();
 
-       DEBUG(transaction->ctx, "Solved request in %.4fms\n",
-               (double)(solving_end - solving_start) * 1000 / CLOCKS_PER_SEC);
+               DEBUG(transaction->ctx, "Solved request in %.4fms\n",
+                       (double)(solving_end - solving_start) * 1000 / CLOCKS_PER_SEC);
 
-       switch (r) {
-               // Solved!
-               case 0:
-                       // Mark as solved
-                       solved = 1;
+               switch (r) {
+                       // Solved!
+                       case 0:
+                               // Mark as solved
+                               solved = 1;
 
-                       // Import the transaction
-                       r = pakfire_transaction_import_transaction(transaction);
-                       if (r)
-                               goto ERROR;
+                               // Import the transaction
+                               r = pakfire_transaction_import_transaction(transaction);
+                               if (r)
+                                       goto ERROR;
 
-                       // Import userinstalled packages
-                       r = pakfire_transaction_import_userinstalled(transaction);
-                       if (r)
-                               goto ERROR;
+                               // Import userinstalled packages
+                               r = pakfire_transaction_import_userinstalled(transaction);
+                               if (r)
+                                       goto ERROR;
 
-                       break;
+#ifdef ENABLE_DEBUG
+                               // Print all decisions
+                               solver_printdecisions(transaction->solver);
+#endif
 
-               // Not Solved
-               default:
+                               goto SOLVED;
+
+                       // Not Solved
+                       default:
 #ifdef ENABLE_DEBUG
-                       // Print all solutions
-                       solver_printallsolutions(transaction->solver);
+                               // Print all solutions
+                               solver_printallsolutions(transaction->solver);
 #endif
 
-                       // Fetch the reason why we could not solve the request
-                       p = pakfire_transaction_get_problem_string(transaction, flags);
+                               // Fetch the reason why we could not solve the request
+                               p = pakfire_transaction_get_problem_string(transaction, flags);
 
-                       if (p) {
-                               DEBUG(transaction->ctx,
-                                       "Could not solve request: %s\n%s\n", selection, p);
+                               if (p) {
+                                       DEBUG(transaction->ctx,
+                                               "Could not solve request: %s\n%s\n", selection, p);
 
-                               // Return the problems
-                               if (problems)
-                                       *problems = strdup(p);
-                       }
+                                       // Return the problems
+                                       if (problems)
+                                               *problems = strdup(p);
+                               }
 
-                       // Ask the user to pick a solution
-                       r = pakfire_ctx_pick_solution(transaction->ctx, transaction->pakfire, transaction);
-                       switch (r) {
-                               case 0:
-                                       goto RETRY;
+                               // Ask the user to pick a solution
+                               r = pakfire_ctx_pick_solution(transaction->ctx, transaction->pakfire, transaction);
+                               switch (r) {
+                                       case 0:
+                                               continue;
 
-                               default:
-                                       goto ERROR;
-                       }
-                       break;
+                                       default:
+                                               goto ERROR;
+                               }
+                               break;
+               }
        }
 
-#ifdef ENABLE_DEBUG
-       if (solved)
-               solver_printdecisions(transaction->solver);
-#endif
-
+SOLVED:
        // Return zero if solved, otherwise return non-zero
        if (solved)
                r = 0;